Yes, we canoverridestart()method of Thread class in Java. We must call thesuper.start()method to create a new thread, and we need to call therun()method in the newly created thread. If we call therun()method directly from thestart()method, it will be executed as a normal method in the actual thread, not in a new thread.
public class ThreadTest { public static void main(String[] args) { MyThread t = new MyThread(); t.start(); } } class MyThread extends Thread { @Override public void start() { // overriding the start() method System.out.println("Overriding a start() method"); super.start(); } @Override public void run() { System.out.println("run() method "); } }
Overriding a start() method run() method
The above is the detailed content of In Java, can we override start() method?. For more information, please follow other related articles on the PHP Chinese website!