Академический Документы
Профессиональный Документы
Культура Документы
try
return;
finally
System.out.println( "Finally" );
A. Finally
B. Compilation fails.
instantiate it.
int x, y;
synchronized(this)
x = 12;
y = 12;
t1.start();
t2.start();
}
A. DeadLock
B. It print 12 12 12 12
C) Compilation Error.
D) Can not determine Output
System.out.println(count++);
a1.start();
a2.start();
ThreadDemo demo;
demo = td;
demo.doSomething();
C. It w ill print the numbers 1 to 20, but the order cannot be determined
2)A thread w ill resume execution as soon as its sleep duration expires.
3)Synchronization can prevent two objects from being accessed by the same thread.
A. 1 and 2 B. 3 and 5
C. 4 and 6 D. 1 and 3
System.out.println(Math.sqrt(-4D));
A. -2
B. NaN
C. Compile Error
D. Runtime Exception
Answers:
1) A)
Explanation :
If you put a finally block after a try and its associated catch blocks, then once execution
enters the try block, the code in that finally block w ill definitely be executed except in the
2) B)
Explanation :
Option B is correct because a static nested class is not tied to an instance of the
enclosing class, and thus can't access the nonstatic members of the class (just as a static
Option A is incorrect because static nested classes do not need (and can't use) a
Option C is incorrect because static nested classes can declare and define nonstatic
members.
Option D is w rong because it just is. There's no rule that says an inner or nested class
3) B)
Explanation : The program will execute w ithout any problems and print 12 12 12 12.
4) B)
Explanation : You have tw o different threads that share one reference to a common object.
The second thread w ill then run to completion printing the numbers 11-20.
5) C)
Explanation : Statements (4) and (6) are correct. (4) is correct because the wait() method is
overloaded to accept a w ait duration in milliseconds. If the thread has not been notified
by the time the wait duration has elapsed, then the thread w ill move back to runnable
synchronized, context. A thread must ow n the lock on the object its invoking
wait()/notify()/notifyAll() on.
(2) is incorrect because a sleeping thread will return to runnable w hen it w akes up, but it
might not necessarily resume execution right aw ay. To resume executing, the new ly
awakened thread must still be moved from runnable to running by the scheduler.
(3) is incorrect because synchronization prevents two or more threads from accessing
6) B)
Explanation : It is not possible in regular mathematics to get a value for the square-root of a
negative
number therefore a NaN w ill be returned because the code is valid.
7) A) True
8) C) SIMULA