Difference Between Thread Class and Runnable Interface in Java

JavaServer Side ProgrammingProgramming

In this post, we will understand the difference between

Thread

  • It is a class.

  • It can be used to create a thread.

  • It has multiple methods such as ‘start’ and ‘run’.

  • It requires more memory space.

  • Since multiple inheritance is not allowed in Java, hence, after a class extends the Thread class, it can’t extend to any other class.

  • Every thread creates a unique object and associates with it.

Runnable

  • It is a functional interface.

  • It can be used to create a thread.

  • It has a single abstract method ‘run’.

  • It requires less memory space.

  • When a class implements the ‘runnable’ interface, the class can extend to other classes.

  • Multiple threads can share the same objects.

raja
Published on 24-Mar-2021 17:09:15
Advertisements