第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

關于靜態(tài)內部類直接訪問外部類的非靜態(tài)成員 new 外部類().成員 能不能賦值

//外部類

public class HelloWorld{

? private int num = 1;

? // 外部類中的靜態(tài)變量score

? private static int score = 84;

??

? // 創(chuàng)建靜態(tài)內部類

public? ? ?static? ? ?class SInner {

? ? ? // 內部類中的變量score

? ? ? int score = 91;

? ? ??

public void show() {

System.out.println("訪問外部類中的score:" +? ? ?HelloWorld.score? ? ? );

System.out.println("訪問內部類中的score:" + score);

HelloWorld hello = new HelloWorld();

System.out.println(hello.num);//這句對的

public int a = hello.num;//這句錯了

}

}


// 測試靜態(tài)內部類

public static void main(String[] args) {

// 直接創(chuàng)建內部類的對象

? ? ? SInner si = new SInner();

? ? ??

? ? ? // 調用show方法

si.show();

System.out.println(si.a);//這句錯了

}

}

上面的這三句

public int a = hello.num;

System.out.println(si.a);

這兩句是錯的

System.out.println(hello.num);

這句是對的


正在回答

2 回答

不好意思,看著這個代碼上的get方法,覺得作用會不會不大?

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

已解決

我把東西寫在函數里了。。。

下面是對的

package com.test.second;


//外部類

public class test2 {

? private int num = 1;

? // 外部類中的靜態(tài)變量score

? private static int score = 84;

??

? // 創(chuàng)建靜態(tài)內部類

public? ? ?static? ? ?class SInner {

? ? ? // 內部類中的變量score

? ? ? int score = 91;

? ? ??

public void show() {

System.out.println("訪問外部類中的score:" +? ? ?test2.score? ? ? );

System.out.println("訪問內部類中的score:" + score);

}

public int getNum() {

return a;

}

// test2 hello = new test2();

// private int a = hello.num;

int a = new test2().num;

}


// 測試靜態(tài)內部類

public static void main(String[] args) {

// 直接創(chuàng)建內部類的對象

? ? ? SInner si = new SInner();

? ? ??

? ? ? // 調用show方法

si.show();

System.out.println(si.a);

}

}


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

舉報

0/150
提交
取消

關于靜態(tài)內部類直接訪問外部類的非靜態(tài)成員 new 外部類().成員 能不能賦值

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

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

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

公眾號

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