• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Difference between extends thread class vs implements runnable interface

 
Rajendra Prakash
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends, can you give difference between extending thread class and implementing runnable interface.
 
manoj r patil
Ranch Hand
Posts: 181
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you extent from Thread, you inherit all from Thread whereas from Runnable you don't get much but run() method.
 
Rajendra Prakash
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not clear . can you explain with other example.
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You most certainly want to implement Runnable rather than extending from Thread. This makes your class more flexible, as you preserve the possibility to extend from another class.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's a FAQ: ExtendingThreadVsImplementingRunnable
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11887
203
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please choose your forum carefully when posting - I have moved this topic to a more appropriate forum.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to Java.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic