Difference between Thread class and Runnable interface in java-
Multiple Inheritance– The limitation with“extends Thread” approach is that if you stretch Thread, you cannot stretch anything else. Java doesn’t support multiple inheritance. In reality, you don’t need Thread class behaviour, because to be able to use a thread you will need to instantiate one anyway. On the other hand, Implementing the Runnable interface gives you the choice to expand any class you want, but nevertheless specify behavior which will be conducted by various thread.
Reusability– In“implements Runnable”, we’re developing a distinct Runnable course for a particular conduct job (if the job that you would like to get performed is project ). It provides us the liberty to reuse the particular Conduct job whenever demanded. “extends Thread” comprises both thread and project special behavior code. Thus once thread finishes execution, it cannot be restart .
Object oriented Design– Implementing Runnable ought to be preferred. It does not specializing or modifying the thread behaviour. You are giving thread something to operate. We conclude that Composition is the better strategy. Composition means two things A and B satisfies has-a relationship. “extends Thread” Isn’t a good Object Oriented practice
Loosely-coupled- If u are implementing Runnable interface then the code will be loosely-coupled and easier to read . Because the code will be divided into two classes. One is Thread for the thread specific code and another with your Runnable implementation class for your job that should be conducted by a thread code. extending Thread class creates the tightly coupled. Single class contains the ribbon code as well as the task that needs to be carried out by the thread.
Functions overhead- extending Thread Means inheriting all the properties of the Thread class which we might don’t need. Job could be performed easily by Runnable without the Thread class functions overhead.(Read Also : Main thread in Java) .