Which cannot directly cause a thread to stop executing?
A -
Calling the SetPriority() method on a Thread object.
B -
Calling the wait() method on an object.
C -
Calling notify() method on an object.
D -
Calling read() method on an InputStream object.
2-
Which method registers a thread in a thread scheduler?
A -
run();
B -
construct();
C -
start();
D -
register();
3-
public class MyRunnable implements Runnable
{
public void run()
{
// some code here
}
}
Which of these will create and start this thread?
A -
new Runnable(MyRunnable).start();
B -
new Thread(new MyRunnable()).start();
C -
new Thread(MyRunnable).run();
D -
new MyRunnable().start();
4-
void start() {
A a = new A();
B b = new B();
a.s(b);
b = null; /* Line 5 */
a = null; /* Line 6 */
System.out.println("start completed"); /* Line 7 */
}
When is the B object, created in line 3, eligible for garbage collection?
A -
after line 5
B -
after line 6
C -
after line 7
D -
There is no way to be absolutely certain.
5-
class X2
{
public X2 x;
public static void main(String [] args)
{
X2 x2 = new X2(); /* Line 6 */
X2 x3 = new X2(); /* Line 7 */
x2.x = x3;
x3.x = x2;
x2 = new X2();
x3 = x2; /* Line 11 */
doComplexStuff();
}
}
after line 11 runs, how many objects are eligible for garbage collection?
A -
0
B -
1
C -
2
D -
3
6-
Which of the following would compile without error?
A -
int a = Math.abs(-5);
B -
int b = Math.abs(5.0);
C -
int c = Math.abs(5.5F);
D -
int d = Math.abs(5L);
7-
What will be the output of the program?
String x = new String("xyz");
String y = "abc";
x = x + y;
How many String objects have been created?
A -
3
B -
4
C -
5
D -
6
8-
What will be the output of the program?
System.out.println(Math.sqrt(-4D));
A -
-2
B -
NaN
C -
Compile Error
D -
Runtime Exception
9-
What will be the output of the program?
public class Test
{
public static void main(String[] args)
{
final StringBuffer a = new StringBuffer();
final StringBuffer b = new StringBuffer();
new Thread()
{
public void run()
{
System.out.print(a.append("A"));
synchronized(b)
{
System.out.print(b.append("B"));
}
}
}.start();
new Thread()
{
public void run()
{
System.out.print(b.append("C"));
synchronized(a)
{
System.out.print(a.append("D"));
}
}
}.start();
}
}
A -
ACCBAD
B -
ABBCAD
C -
CDDACB
D -
Indeterminate output
10-
Which statement is true given the following?
Double d = Math.random();