This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
i have doubt in difference between implementing runnable and extending Thread class?
what i understood by reading is while we implement runnable , we use Thread class reference and pass the reference of the run() method thread, and we need to call the run() explicitlly,even when we use it inside a consructor...
but in using extending Thread class we need not to pass such reference and we only need create the reference for run() thread class if we use the constructor for that class... we even need not to call the run() methjod explicitlly....
this what i have understood!!! am i correct ? please make me clear about this?
Shin Kudo wrote:When your class extends Thread, it can't extend any other classes. That's why the Runnable's way is preferred
Yes very true. But there is one more important factor to this. When do we sub-class a class...when we want a more specific behaviour of the super-class...so sub-class the thread class only when you want a more specific behaviour of the thread class or else implement the Runnable interface and override the run(). So be careful about how you choose to implement the thread behaviour (OO Concepts are the heart of Java ) .