实例 Java 通过扩展 thread 类来运行线程

x
 
public class Main extends Thread {
  public static void main(String[] args) {
    Main thread = new Main();
    thread.start();
    System.out.println("This code is outside of the thread");
  }
  public void run() {
    System.out.println("This code is running in a thread");
  }
}
                    

输出结果

This code is outside of the thread
This code is running in a thread