aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes run() method Doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "run() method Doubt" Watch "run() method Doubt" New topic
Author

run() method Doubt

Gitesh Ramchandani
Ranch Hand

Joined: Feb 28, 2007
Posts: 274
The following code compiles and runs successfully:



I was thinking as run() is not explicitly defined and implemented, it will give compiler error

Is the compiler intelligent enough to find that a run() method is available in the Thread class, so it is ignoring the implementation of Runnable interface?

Please help,

Thanks,
Gitesh
Jelle Klap
Bartender

Joined: Mar 10, 2008
Posts: 1666
    
    7

If you extend Thread you implicitly implement Runnable, because Thread IS-A Runnable. As Thread is not an abstract class it must provide an implemenation of the run() method, which it does; an empty one. Therefore you don't have to implement the run() method in your Thread subclass, even if you explicitly specify that it should implement the Runnable interface. It just doesn't make any sense not to override the run() implementation you inherit from the Thread class, because it does nothing and returns, which isn't terribly usefull.
[ March 27, 2008: Message edited by: Jelle Klap ]

Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Gitesh Ramchandani
Ranch Hand

Joined: Feb 28, 2007
Posts: 274
Thanks Jelle
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: run() method Doubt
 
Similar Threads
Which thread Constructor is called?
can anybody tel me wat exactly Thread.start() will do?
Thread question
Passing parameters from parent method to an inline class defined inside the method
Instantiating a Thread page no 679