Creating and Running Threads
class MyThread extends Thread {
public void run() {
System.out.println("Thread running...");
}
}
public class ThreadExample {
public static void main(String[] args) {
MyThread myThread = new MyThread();
myThread.start(); // Start the thread
}
}class MyRunnable implements Runnable {
public void run() {
System.out.println("Thread running...");
}
}
public class RunnableExample {
public static void main(String[] args) {
Thread thread = new Thread(new MyRunnable());
thread.start(); // Start the thread
}
}Last updated