This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes Threads and Synchronization and the fly likes extends Thread  Vs  implements Runnable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "extends Thread  Vs  implements Runnable" Watch "extends Thread  Vs  implements Runnable" New topic
Author

extends Thread Vs implements Runnable

kri shan
Ranch Hand

Joined: Apr 08, 2004
Posts: 1392
Both are implementing run() method. If i choose Runnable interface, supports multiple interface inheritance. Why do we need Thread class ?
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
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.


JDBCSupport - An easy to use, light-weight JDBC framework -
Ulf Dittmer
Rancher

Joined: Mar 22, 2005
Posts: 42956
    
  73
This may help: http://faq.javaranch.com/java/ExtendingThreadVsImplementingRunnable
 
 
subject: extends Thread Vs implements Runnable
 
It's not a secret anymore!