Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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

extends Thread Vs Implements Runnable

 
Ranch Hand
Posts: 1491
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What are the main difference betweeen extends Thread and Implements Runnable other than basic difference ?
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic