in Technology 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 Thread class

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
    Which of these method is used to implement Runnable interface? (a) stop() (b) run() (c) runThread( ... division Multithreading of Java Select the correct answer from above options...
asked Mar 1, 2022 in Education by JackTerrance
0 votes
0 votes
    Differentiate between process and thread?...
asked Jan 19, 2021 in Technology by JackTerrance
0 votes
    Which of this interface is implemented by Thread class? (a) Runnable (b) Connections (c) Set (d) ... programming questions and answers pdf, java interview questions for beginners...
asked Oct 25, 2021 in Education by JackTerrance
0 votes
    Which of the interface contains all the methods used for handling thread related operations in Java? (a) ... questions and answers pdf, java interview questions for beginners...
asked Oct 25, 2021 in Education by JackTerrance
0 votes
    What is the difference between an abstract class and an interface?...
asked Feb 9, 2023 in Technology by JackTerrance
0 votes
    What is the difference between abstract class and interface in C#?...
asked Jul 27, 2021 in Technology by JackTerrance
0 votes
    Before... (question deleted) I'm trying to make a runnable jar from a Swing project. I add some ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 20, 2022 in Education by JackTerrance
0 votes
    The strategy of making processes that are logically runnable to be temporarily suspended is called : Select the correct answer from above options...
asked Nov 27, 2021 in Education by JackTerrance
0 votes
    Differentiate between TOS for Data Integration and TOS for Big Data?...
asked Mar 23, 2021 in Technology by JackTerrance
0 votes
    Differentiate between TOS for Data Integration and TOS for Big Data....
asked Mar 23, 2021 in Technology by JackTerrance
0 votes
    Which of the following class in Bootstrap is used for creating the large size modals? .modal-large .modal-sm .modal-big .modal-lg...
asked Mar 2, 2021 in Technology by JackTerrance
0 votes
    The class used for creating the small size wells is .well-small .well-short .well-lg .well-sm...
asked Mar 2, 2021 in Technology by JackTerrance
0 votes
    The class used for creating the large size wells is .well-large .well-big .well-lg .well-sm...
asked Mar 2, 2021 in Technology by JackTerrance
0 votes
    Just curious to know on whether we can sort a List according to the frequency of repeated numbers using ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
...