0 votes
in JAVA by
Differentiate between the Thread class and Runnable interface for creating a Thread?

1 Answer

0 votes
by

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().

Related questions

0 votes
asked May 7, 2021 in JAVA by sharadyadav1986
0 votes
0 votes
asked Aug 21, 2022 in JAVA by sharadyadav1986
...