aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question onThread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Question onThread" Watch "Question onThread" New topic
Author

Question onThread

Subha Garg
Ranch Hand

Joined: Feb 28, 2008
Posts: 39
Given Notice the use of anonymous inner class)


What is the answer:
A. Cat
B. Dog
C. Compilation fails.
D. The code runs with no output.
E. An exception is thrown at runtime.
Nadeem Khan
Ranch Hand

Joined: Nov 27, 2007
Posts: 108
Dog. Coz your code instantiates the anonymous class extending Thread and assigns the object reference to t.


<i>If there were no Exceptions (not Errors!), Life would have kinda sucked!!</i>
Subha Garg
Ranch Hand

Joined: Feb 28, 2008
Posts: 39
But isn't there a rule that says the runnable object that is passed to the thread gets its run method called.
Nadeem Khan
Ranch Hand

Joined: Nov 27, 2007
Posts: 108
If you didnt have that anonymous class definition , it would have constructed a Thread object using the constructor Thread(Runnable r). BUT here your code instantiates a subclass of Thread (not the Thread class), declared anonymously and assigns its ref to "t". Anonymous class has to do what its created for.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Question onThread