Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

extends Thread Vs Implements Runnable  RSS feed

 
kri shan
Ranch Hand
Posts: 1487
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are the main difference betweeen extends Thread and Implements Runnable other than basic difference ?
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess answered many times.
But long story short:
If you want to create your own specific Thread object then subclass Thread, otherwise just implement Runnable.
[ June 30, 2005: Message edited by: Yilmaz Mete ]
 
samdeep aarzoo
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java doesnt support multiple inheritance
for eg in applet we want to have a thread ,
but since an applet extends from applet
class so we cannot directly include a run method
that is why runnable interface come in picture
with this reference we make a reference to the
runnable object which then calls the run method
therefore we can have multithreads that dont necessary
inherit from a thread class

class animation extends Applet impliments Runnable
public void run()
{
// thread code here
}


hope this helps u
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For me, this is just a Java question, namely why do you want to write a subclass? Answer: if you wish to make an addition or alteration to the behaviour of the base class. I often find that there is no need to subclass Thread, so implementing the Runnable interface is the correct solution.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!