Monday, August 9, 2010

Multithreading: MyThread.java

Courtesy of SCJP Sun® Certified Programmer for Java™ 6 Study Guide Exam (310-065) (9780071591065)
Chapter 9, Question 2



 
 
 
 
 
 
 
 
 
 
 
What is the result of this code?

A.   Compilation fails

Incorrect because the Thread class implements the Runnable interface; therefore, in line 5, Thread can take an object of type Thread as an argument in the constructor (this is NOT recommended).



B.   1..2..3..

Incorrect because the variable i in the for loop starts with a value of 0 and ends with a value of 2.



C.   0..1..2..3..

Incorrect because the variable i in the for loop starts with a value of 0 and ends with a value of 2.


D.   0..1..2..

Correct. The thread MyThread will start and loop three times (from 0 to 2).


E.   An exception occurs at runtime

Incorrect based on the above.

No comments:

Post a Comment