为了账号安全,请及时绑定邮箱和手机立即绑定

No enclosing instance of type Actor is accessible. Must qualify the allocation with an enclosing instance of type Actor (e.g. x.new A() where x is an instance of Actor).

public class Actor extends Thread {
public void run(){
System.out.println(getName()+"是一个演员");
int count=0;
boolean keeprunning=true;
while(keeprunning){
System.out.println(getName()+"登台演出"+(++count)+"次");

if(count==100){
keeprunning=false;
}

if(count%10==0){
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
System.out.println(getName()+"演出结束了");
}
class Actress implements Runnable{

@Override
public void run() {
// TODO Auto-generated method stub
System.out.println(Thread.currentThread().getName()+"是一个演员");
int count=0;
boolean keeprunning=true;
while(keeprunning){
System.out.println(Thread.currentThread().getName()+"登台演出"+(++count)+"次");

if(count==100){
keeprunning=false;
}

if(count%10==0){
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
System.out.println(Thread.currentThread().getName()+"演出结束了");

}

}
public static void main(String[] args) {
Thread actor=new Actor();
actor.setName("MESSI");
actor.start();
Thread actressThread=new Thread(new Actress(),"C.Ronaldo");

actressThread.start();
}
}



正在回答

4 回答

也可以全部写在里面,但是要用static class Actress implements Runnable{}来创建这个类。也就是必须声明是静态的。

0 回复 有任何疑惑可以回复我~

原来如此。。。

0 回复 有任何疑惑可以回复我~

问题已解决,不应该吧Actress类卸载Actor类里面

0 回复 有任何疑惑可以回复我~

http://img1.sycdn.imooc.com//58072fa100019d1008820110.jpg

提示的错误是这样的

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

No enclosing instance of type Actor is accessible. Must qualify the allocation with an enclosing instance of type Actor (e.g. x.new A() where x is an instance of Actor).

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信