Yes, we can override start() method of Thread class in Java. We must call the super.start() method to create a new thread, and we need to call the run() method in the newly created thread. If we call the run() method directly from the start() 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"); <strong> </strong>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!