public class Demo1_Thread {
public static void main(String[] args) throws InterruptedException {
Demo demo = new Demo(); //4.创建Thread类的子类对象
demo.start(); //5.开启线程
for(int i = 0; i<10; i++) {
System.out.println("BBBBBBBBBBBBBBBBBBBB");
Thread.sleep(100);
}
}
}
class Demo extends Thread{ //1.继承Thread类
public void run() { //2.重写run方法
for (int i = 0; i < 10; i++) { //3.将要执行的代码写在run方法内
System.out.println("AAAAAAAAAAAAAAAAAAAAAA");
try {
sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}