What happens if we don’t override run() method during thread creation using extended thread?


If we don’t override run() method, compiler will not flash any error and it will execute run() method of Thread class that has empty implemented, So, there will be no output for this thread.

Below example will not provide any output


public class Sample extends Thread  {

	public static void main(String[] args) {	
		Thread t = new Thread( new Sample());
		t.start(); // will create a new thread and call thread class's run() method which has no implementation.




This is one of the advantages of Runnable interface over extending Thread class. Runnable interface forces you to override run() method.

Leave a Comment