為什么運(yùn)行失敗
public class HelloWorld {
? ??
? ? private String name = "愛慕課";
? ??
? ? // 外部類中的show方法
? ? public void show() {?
// 定義方法內(nèi)部類
class MInner {
int score = 83;
public int getScore() {
return score + 10;
}
}
? ? ? ??
// 創(chuàng)建方法內(nèi)部類的對(duì)象
? ? ? ? MInner mi=new MInner();
? ? ? ??
? ? ? ??
? ? ? ? // 調(diào)用內(nèi)部類的方法
return mi.getScore();
? ? ? ??
System.out.println("姓名:" + name + "\n加分后的成績(jī):" + newScore);
}
? ??
// 測(cè)試方法內(nèi)部類
public static void main(String[] args) {
? ? ? ??
// 創(chuàng)建外部類的對(duì)象
? ? ? ? HelloWorld mo=new HelloWorld();
? ? ? ??
? ? ? ? // 調(diào)用外部類的方法
mo.show();
}
}
出現(xiàn)運(yùn)行失敗,就是找不出問題
2018-03-20
沒定義newScore
int newScore=mi.getScore();
這樣就可以運(yùn)行了
2018-06-09
一,二樓正解
2018-04-10
二樓加一