Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes class extends thread-- shud u define run method? 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 "class extends thread-- shud u define run method?" Watch "class extends thread-- shud u define run method?" New topic
Author

class extends thread-- shud u define run method?

mythili sharan
Greenhorn

Joined: Sep 23, 2004
Posts: 4
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

Joined: Sep 02, 2004
Posts: 83
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.
 
jQuery in Action, 2nd edition
 
subject: class extends thread-- shud u define run method?
 
Similar Threads
Thread2
Threads: start() and run() methods
could you pls explain this code and the output.
Thread
Marcus Green Mock # 2 Ques. 18, 33, 51