• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question onThread

 
Subha Garg
Ranch Hand
Posts: 39
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 108
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dog. Coz your code instantiates the anonymous class extending Thread and assigns the object reference to t.
 
Subha Garg
Ranch Hand
Posts: 39
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 108
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic