请求解释,两个不知道的错误:不兼容的类型和name可以在Thread中访问private
class MyThread extends Thread {
private int time;
public MyThread(String name ,int time){
super(name);
this.name = name;
}
public void run() {
try {
Thread.sleep(this.time);
}catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(Thread.currentThread().getName() + "线程,休眠" + this.time + "毫秒");
}
}
public class ExceDemo1{
public static void main(String[] args) {
MyThread mt1 = new MyThread("线程A",10000);
MyThread mt2 = new MyThread("线程B",20000);
MyThread mt3 = new MyThread("线程C",30000);
mt1.start();
mt2.start();
mt3.start();
}
}
------解决方案--------------------你这肯定没有用Eclipse.
复制到Eclipse里面一眼就看出来错误了。、
public MyThread(String name ,int time){
super(name);
this.name = name;
}
你继承的是Thread
Thread的构造方法里面有
super(name);
么?
public MyThread(String name ,int time){
this.time=time;
this.name = name;
}