Java Multi-Threading Question:
Download Questions PDF

Explain the method of Thread class with example?

Java Multi-Threading Interview Question
Java Multi-Threading Interview Question

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 Interview Questions And Answers PDF

Previous QuestionNext Question
What is Thread leak?What are the different states of a threads lifecycle?