Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

class extends thread-- shud u define run method?

 
mythili sharan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This question too is from Marcus green's mock exam.
when we extend thread or implement runnable-- isnt it necessary to define the run method?? I can compile and check but what confuses me is how to tackle such a basics- shattering qn in the exam.

I thought the answer would be 1 but it is 4.



(Reformated)
[ September 24, 2004: Message edited by: Barry Gaunt ]
 
Tom Tolman
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you implement Runnable, you need to define the run, since the Runnable interface has an abstract method run.

However, Thread is not an abstract class, and does implement run. It calls the Runnable if it has one, or else does nothing and returns.

Therefore, you can extend Thread and not implement run, but it won't allow you to utilize it as a separate thread, but you can utilize the class normally.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic