创建新的类并继承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);
}
}
}