• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

run() method Doubt

 
Ranch Hand
Posts: 274
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Gitesh Ramchandani
Ranch Hand
Posts: 274
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Jelle
reply
    Bookmark Topic Watch Topic
  • New Topic