This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
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
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply 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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: class extends thread-- shud u define run method?
 
Similar Threads
Thread
Threads: start() and run() methods
Marcus Green Mock # 2 Ques. 18, 33, 51
Thread2
could you pls explain this code and the output.