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

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

請問怎么會提示錯誤呢?

https://img1.sycdn.imooc.com//5cbed6b30001565f06260206.jpg

https://img1.sycdn.imooc.com//5cbed6b400018e6007580094.jpg

package com.xuanxuan;


public class Actor extends Thread {

public void run() {

System.out.println(getName()+"是一個演員");

int count=0;

boolean keepRuning=true;

while(keepRuning) {

System.out.println(getName()+"登臺演出"+(++count));

if(count==100) {

keepRuning=false;

}

if(count%10==0) {

try {

Thread.sleep(2000);

} catch (InterruptedException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

System.out.println(getName()+"演出結束了");

}

class Actress implements Runnable{

public void run() {

System.out.println(Thread.currentThread().getName()+"是一個演員");

int count=0;

boolean keepRuning=true;

while(keepRuning) {

System.out.println(Thread.currentThread().getName()+"登臺演出"+(++count));

if(count==100) {

keepRuning=false;

}

if(count%10==0) {

try {

Thread.sleep(2000);

} catch (InterruptedException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

System.out.println(Thread.currentThread().getName()+"演出結束了");

}

}


public static void main(String[] args) {

// TODO Auto-generated method stub

Thread actor=new Actor();

actor.setName("先生");

Thread actressThread=new Thread(new Actress(),"女士");

actor.start();

actressThread.start();

}


}


正在回答

3 回答

class Actress implements Runnable{

public void run() {

System.out.println(Thread.currentThread().getName()+"是一個演員");

int count=0;

boolean keepRuning=true;

while(keepRuning) {

System.out.println(Thread.currentThread().getName()+"登臺演出"+(++count));

if(count==100) {

keepRuning=false;

}

if(count%10==0) {

try {

Thread.sleep(2000);

} catch (InterruptedException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

System.out.println(Thread.currentThread().getName()+"演出結束了");

}

}

這個class Actress叫做內部類,他和public class Actor是同級的,所以Actress應該放在Actor的大括號的外面。

0 回復 有任何疑惑可以回復我~
#1

tiger愛小狄

有一句話我說的不對 class Actress不是內部類
2019-07-05 回復 有任何疑惑可以回復我~

Actress類放外面。不是放在Actor里面的

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

在你的Actress類前面加個static

0 回復 有任何疑惑可以回復我~
#1

劍雨319

原理應該是靜態方法會先加載?而你的內部類Actress不是靜態方法還不存在?大概就是這個意思吧
2019-04-24 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

請問怎么會提示錯誤呢?

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

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

公眾號

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