You need to store elements in a collection that guarantees that no duplicates are stored and all elements can be accessed in natural order. Which interface provides that capability?
A -
java.util.Map
B -
java.util.Set
C -
java.util.List
D -
java.util.Collection
2-
/* Missing Statement ? */
public class foo
{
public static void main(String[]args)throws Exception
{
java.io.PrintWriter out = new java.io.PrintWriter();
new java.io.OutputStreamWriter(System.out,true);
out.println("Hello");
}
}
What line of code should replace the missing statement to make this program compile?
A -
No statement required.
B -
import java.io.*;
C -
include java.io.*;
D -
import java.io.PrintWriter;
3-
Which is true about an anonymous inner class?
A -
It can extend exactly one class and implement exactly one interface.
B -
It can extend exactly one class and can implement multiple interfaces.
C -
It can extend exactly one class or implement exactly one interface.
D -
It can implement multiple interfaces regardless of whether it also extends a class.
4-
public class MyOuter
{
public static class MyInner
{
public static void foo() { }
}
}
which statement, if placed in a class other than MyOuter or MyInner, instantiates an instance of the nested class?
A -
MyOuter.MyInner m = new MyOuter.MyInner();
B -
MyOuter.MyInner mi = new MyInner();
C -
MyOuter m = new MyOuter();
D -
MyInner mi = new MyOuter.MyInner();
5-
Which two are valid constructors for Thread?
Thread(Runnable r, String name)
Thread()
Thread(int priority)
Thread(Runnable r, ThreadGroup g)
Thread(Runnable r, int priority)
A -
1 and 3
B -
2 and 4
C -
1 and 2
D -
2 and 5
6-
Which two of the following methods are defined in class Thread?
start()
wait()
notify()
run()
terminate()
A -
1 and 4
B -
2 and 3
C -
3 and 4
D -
2 and 4
7-
Under which conditions will a currently executing thread stop?
When an interrupted exception occurs.
When a thread of higher priority is ready (becomes runnable).
When the thread creates a new thread.
When the stop() method is called.
A -
1 and 3
B -
2 and 4
C -
1 and 4
D -
2 and 3
8-
Which statement is true?
A -
The notifyAll() method must be called from a synchronized context.
B -
To call wait(), an object must own the lock on the thread.
C -
The notify() method is defined in class java.lang.Thread.
D -
The notify() method causes a thread to immediately release its locks.
9-
public Object m()
{
Object o = new Float(3.14F);
Object [] oa = new Object[l];
oa[0] = o; /* Line 5 */
o = null; /* Line 6 */
oa[0] = null; /* Line 7 */
return o; /* Line 8 */
}
When is the Float object, created in line 3, eligible for garbage collection?
A -
just after line 5
B -
just after line 6
C -
just after line 7
D -
just after line 8
10-
What will be the output of the program?
String a = "ABCD";
String b = a.toLowerCase();
b.replace('a','d');
b.replace('b','c');
System.out.println(b);