Running threads

With the help of a call to the method start() the thread is started and the further execution is transferred to the method run. start is terminated after starting the thread and the caller can continue in parallel with the newly created thread.

By extending thread class

public class MyThread extends Thread {
	public void run() {
		System.out.println("Thread is running");
	}

	public static void main(String[] args) {
		MyThread thread = new MyThread();
		thread.start();
	}
}
Output
Thread is running

By implementing runnable class

public class MyThread implements Runnable {
	public void run() {
		System.out.println("Thread is running");
	}

	public static void main(String[] args) {
		MyThread obj = new MyThread();
		Thread thread = new Thread(obj);
		thread.start();
	}
}
Output
Thread is running