亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

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下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號