关于多线程Thread的简单应用

创建新的类并继承Thread(Thread必须重写run()方法)

public class MyThread extends Thread{
public static void main(String[] args) {

}

@Override 
  //重写run()方法
public void run() {
    for (int i = 0; i < 200; i++) {
        System.out.println("李四"+i);
    }
    super.run();
}

}
创建另一个Demo新类,然后创建线程对象

public class Demo01 {
public static void main(String[] args) {
MyThread myThread=new MyThread();
myThread.start();//启动线程
for (int i = 0; i < 200; i++) {
System.out.println("张三"+i);
}
}

}

posted @ 2020-11-04 19:38  蒋先生Terry  阅读(98)  评论(0编辑  收藏  举报