Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

implements Runnable and extending Thread

 
Mohanasundaram Govindarajan
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Which one is the best to create the Thread. i.e Implements Runnable or extends Thread.

I know that if we create thread by extending Thread class, multiple inheritance is not possible. So we can create thread by implementing Runnable to overcome this.

I want to Know if my class does not have super class , then which one is the best,Please justify.
 
Naishadh Parmar
Ranch Hand
Posts: 95
C++ Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mohan,

First of all welcome to Ranch!!!
If you have to inherit a class already then I recommend "implements Runnable" because as you know a class cannot inherit multiple classes.
If you don't have to inherit any class then you can use either
 
Stephan van Hulst
Bartender
Pie
Posts: 5790
61
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. *Always* implement Runnable. Your class is not a Thread, so it shouldn't extend it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic