Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

extends Thread Vs implements Runnable

 
kri shan
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Both are implementing run() method. If i choose Runnable interface, supports multiple interface inheritance. Why do we need Thread class ?
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you implement Runnable you still have to pass your class to a Thread if you want to start it. Following the 'Favor Composition Over Inheritance' you most likely are always better off implementing Runnable than extending Thread.
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic