Create a class that extends from thread and have an example - Java:
public class ThreadExample extends Thread {
/**
* This method is the constructor of the class.
* @param name name of the thread.
*/
public ThreadExample(String name) {
super(name);
}
/**
* This method is the run method of the class.
*/
public void run() {
//Print the name of the thread
System.out.println("Thread name is :" + getName());
}
/**
* One Example
*/
public static void main(String args[]) throws IOException {
ThreadExample threadExample= new ThreadExample ("Thread 1");
//Start the thread
threadExample.start();
//Example 2
ThreadExample threadExample2= new ThreadExample ("Thread 2");
//Start the thread
threadExample2.start();
}
}
Top comments (0)