Why does Java have two ways to create child threads? Which way is better? Java threads can be created graciously in two ways: implementing the Runnable interface and extending Thread class.
Extending the class inherits the methods and data members, fields from the class Tread. In this process only one class can be inherited from the parent class Thread.
Implementing Runnable interface overcomes the limitation of inheriting from only one parent class Thread. Using Runnable interface, lays a path to ground work of a class that utilizes threads. The advantage is a class can extend Thread class and also implements the Runnable interface, if required. The Runnable interface is set for implementing a thread and the class that implements the interface performs all the work.
|