继承Thread类
1.子类覆盖父类中的run方式,将线程运行的代码存放在run中
2.建立子类对象的同时线程也被创建。
3.通过调用start方法开启线程。
class Demo extends Thread{
public void run(){
for (int x = 0; x <150 ; x++ ){
System.out.println("TestDemo");
}
}
}
public class TestDemo{
public static void main(String[] args){
Demo d = new Demo();
d.start();
for(int x = 0 ; x <10; x++){
System.out.println("d" + x);
}
}
}