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
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: 1763
    
    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
 
Don't get me started about those stupid light bulbs.
 
subject: run() method Doubt