20行和32行的兩個(gè)調(diào)用有什么作用
//外部類
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)部類的對象
??????? MInner mi = new MInner();
???????
??????? // 調(diào)用內(nèi)部類的方法
?//?mi.getScore();
???????
??System.out.println("姓名:" + name + "\n加分后的成績:" + mi.getScore());
?}
???
?// 測試方法內(nèi)部類
?public static void main(String[] args) {
???????
??// 創(chuàng)建外部類的對象
??????? HelloWorld mo = new HelloWorld();
???????
??????? // 調(diào)用外部類的方法
??//mo.show();
?}
}
2017-12-10
20行 獲取內(nèi)部類的返回值int newScore=m.getScore(); 存在變量newScore中
32行 主函數(shù)實(shí)例化HelloWorld對象mo,調(diào)用show()函數(shù)才能實(shí)例化內(nèi)部類