Java Multi-Threading Question:

Explain the method of Thread class with example?

Tweet Share WhatsApp

Answer:

In this method of creating thread, we have to extend the Thread class and override the run() method in our class to create a Thread.
We have to create an object of the our class.
Once the object is created then we have to invoke the start() method and it will generate a new thread of execution.

For example

public class MyThread extends Thread{
public void run(){
// code to execute under the thread
}
public static void main(String [] args){
MyThread c = new MyThread();
c.start();
}
}

Download Java Multi-Threading PDF Read All 36 Java Multi-Threading Questions
Previous QuestionNext Question
What is Thread leak?What are the different states of a threads lifecycle?