這個(gè)錯(cuò)誤是什么?HelloWorld.java:17: error: expected System.out.println(score1 + "\n加分后的成績:" + newScore);
//外部類
public class Wbl{
? ? private int score1 = 40;
? ??
? ? // 外部類中的show方法
? ? public void show(){
? ? ? ? // 定義方法內(nèi)部類
? ? ? ? class MInner{
? ? ? ? ? ? int score2 = 44;
? ? ? ? ? ? public int getScore(){
? ? ? ? ? ? ? ? return score1 + score2;
? ? ? ? ? ? }
? ? ? ? ? ? // 創(chuàng)建方法內(nèi)部類的對象
? ? ? ? ? ? MInner mi = new MInner();
? ? ? ? ? ? // 調(diào)用內(nèi)部類的方法
? ? ? ? ? ? int newScore = mi.getScore();
? ? ? ? ? ? System.out.println(score1 + "\n加分后的成績:" + newScore);
? ? ? ? }
? ? }
? ??
? ? // 測試方法內(nèi)部類
public static void main(String[] args) {
? ? ? ??
// 創(chuàng)建外部類的對象
? ? ? ? Wbl mo=new Wbl();
? ? ? ??
? ? ? ? // 調(diào)用外部類的方法
mo.show();
}
}
2018-12-04
你創(chuàng)建方法內(nèi)部類的對象寫錯(cuò)了,
你寫在方法內(nèi)部類中,
代碼需要寫在外部類中。
2018-12-03
兄弟。你的大括號打錯(cuò)地方了,也可以說是,,,你的創(chuàng)建方法內(nèi)部類的對象和調(diào)用 寫錯(cuò)地方了。
2018-12-03
public int score1 = 40;