Java Threads Question:
Download Questions PDF

Why not override Thread to make a Runnable?

Answer:

There is little difference in the work required to override the Thread class compared with implementing the Runnable interface, both require the body of the run() method. However, it is much simpler to make an existing class hierarchy runnable because any class can be adapted to implement the run() method. A subclass of Thread cannot extend any other type, so application-specific code would have to be added to it rather than inherited.

Separating the Thread class from the Runnable implementation also avoids potential synchronization problems between the thread and the run() method. A separate Runnable generally gives greater flexibility in the way that runnable code is referenced and executed.

Download Java Threads Interview Questions And Answers PDF

Previous QuestionNext Question
A Thread is runnable, how does that work?What is the difference between a threads start() and run() methods?