首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java相关 >

请求解释,两个不知道的异常:不兼容的类型和name可以在Thread中访问private

2013-10-21 
请求解释,两个不知道的错误:不兼容的类型和name可以在Thread中访问privateclass MyThread extends Thread

请求解释,两个不知道的错误:不兼容的类型和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();
}
}
thread 类 线程
[解决办法]
你这肯定没有用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;
}

热点排行