Differentiate between the Thread class and Runnable interface for creating a Thread?
Differentiate between the Thread class and Runnable interface for creating a Thread?
Answer
The Thread can be created by using two ways.
By extending the Thread class
By implementing the Runnable interface
However, the primary differences between both the ways are given below:
By extending the Thread class, we cannot extend any other class, as Java does not allow multiple inheritances while implementing the Runnable interface; we can also extend other base class(if required).
By extending the Thread class, each of thread creates the unique object and associates with it while implementing the Runnable interface; multiple threads share the same object
Thread class provides various inbuilt methods such as getPriority(), isAlive and many more while the Runnable interface provides a single method, i.e., run().
Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website.
If you are using this website then its your own responsibility to understand the content of the website