Prev Next

Java / Java Multithreading part II

Can you override Thread start method?

Yes, however doing so invoking start method will execute start on the same thread and it will neither create new thread nor call run method.

public class ThreadOverrideStart extends Thread{
	
	@Override
	public void run() {
		System.out.println("Running in " + Thread.currentThread().getName());
	}
	
	@Override
	public void start() {
		System.out.println(" Hello from start method");
	}
	
	
	public static void main(String[] args) {
		ThreadOverrideStart th = new ThreadOverrideStart();
		th.start();
	}

}

In the above program, both the run and start method are overridden. Some may expect that the start method will invoke the run method but it won't. Invoking start method works like any other method and will not invoke run method at all.

Output:

 Hello from start method

❤Cash Back At Stores you Love !!!❤

Earn your $10 reward when you make your first purchase through Ebates by signing up with clicking below button.

Ebates Coupons and Cash Back

More Related questions...

Show more question and Answers...

final keyword

Comments & Discussions