关于线程的有关问题,求大神指点

   阅读
关于线程的问题,求大神指点
为什么我在构造时传递的名字没有反应,打印出来的名字还是Thread0和Thread1
而不是one和two
能说明原因吗?
class thread extends Thread
{
private String name;
thread(String name)
{
this.name=name;
}
public void run()
{
for(int a=0;a<60;a++)
{
System.out.println(this.getName()+""+a);
}
}
}
class day1106
{
public static void main(String[]args)
{
thread t=new thread("one----");
thread t1=new thread("two===");
t.start();
t1.start();
}
}
多线程

------解决方案--------------------

class thread extends Thread
{
private String name;
thread(String name)
{
super(name);
}
public void run()
{
for(int a=0;a<60;a++)
{
System.out.println(this.getName()+""+a);
}
}
}
class Demo12
{
public static void main(String[]args)
{
thread t=new thread("one----");
thread t1=new thread("two===");
t.start();
t1.start();
}
}

因为你没有把name赋给Thread,你在构造函数 里面调用父类的函数就可以啦。。。。我已经帮你改好了
阅读
上一篇:新手求教个有关问题 下一篇:返回列表