public class Demo10 extends Thread{
private String name;
public Demo10(String name) {
super(name);
}
//重写run()方法
@Override
public void run() {
for(int x=0;x<10;x++){
System.out.println(name+"...x="+x+"...name="+Thread.currentThread().getName());
}
}
public static void main(String[] args) {
Demo10 d1=new Demo10("狗娃");
Demo10 d2=new Demo10("铁蛋");
d1.start();//开启线程,调用run()方法
d2.start();
System.out.println("over..."+Thread.currentThread().getName());
}
}
疑问:为什么输出结果中name的值是null呀
|
|