• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

thread

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can you please clear this up for me?
For extending thread and implementing runnable, which one implements run and which one overrides run.
thanks,
yuki
 
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
both the way of creating a thread have to override the run method
 
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when u implement an interface u have to give body to all its methods if the class is not declared an abstract one, so in case of Runnable u have to define run method.while in case of extending Thread if u don't define the run method the thread would run but would not do anything as its default version in the Thread class is empty.hope this clears ur doubt.
 
Yuki Cho
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
so, when extending a thread, we say override the run() method. And for implementing Runnable, we can either say implement run() method or override the run() method. Or both ways can only be overriding the run() method.
thanks,
Yuki
 
kriti sharma
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
defining an abstract method is also called overriding of an abstract method. so both ways u can say is a case of overriding.but i wonder why u r going so specific???
 
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Yuki and Kriti


so, when extending a thread, we say override the run() method. And for implementing Runnable, we can either say implement run() method or override the run() method. Or both ways can only be overriding the run() method.


When you are implementing an interface you neccessarily impliment the methods. The reasons is the methods are
abstract implicitely. Ofcourse, while impliment you may
skip some methods and not impliment them, then in such a situation you need to declare the implimenting class as an abstract class.
Focussing on the current question. Runnable interface has just
one method viz., <code>run()</code>. So , when you are implementing multithreading by implimenting the "Runnable" you
"implement" the run() method. What you are doing in this case is defining it (as it already declared in the interface). On the other hand, in case of extending "Thread" you overide the
run() method as in the Thread class we already have a body
of the run() method which does nothing.
Hope this clears the doubt.
Ravindra Mohan.
 
Yuki Cho
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks everybody for replying my question. i got it now. :P
-yuki
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic