Multithreading
Java Program to Create Thread by Extending Thread Class
A Java program to create a thread by extending the Thread class.
Problem Description
Write a Java program to create a thread by extending the Thread class.
Code
class MyThread extends Thread {
public void run() {
System.out.println("Thread is running...");
}
}
public class ExtendThread {
public static void main(String[] args) {
MyThread t1 = new MyThread();
t1.start();
}
}Output
Thread is running...Explanation
extends Thread: Inherit from the Thread class.run(): Override the run method to define the thread's action.start(): Call start method to begin execution of the thread.
