不能在成員內(nèi)部類中創(chuàng)建和外部類同名的靜態(tài)變量嗎?
public ?class HelloWorld {
? ? private static int score = 84;
? public ? class SInner {
static ?int ?score = 91;
? ? ? public void show() {
System.out.println("訪問(wèn)外部類中的score:" +HelloWorld.this.score ? ? ? ? ?);
System.out.println("訪問(wèn)內(nèi)部類中的score:" + score);
}
}public static void main(String[] args) {
HelloWorld i=new HelloWorld();
? ? ? ? SInner si=i.new SInner();
? ? ? ? ?si.show();
}
}
-------------------------------------------
為什么我這段代碼會(huì)報(bào)錯(cuò)?
2017-08-13
這個(gè)在課程里面說(shuō)的很清楚:內(nèi)部類中不允許定義靜態(tài)變量..
2017-08-13
只有在靜態(tài)內(nèi)部類中才能聲明靜態(tài)變量?。?!
2017-08-13
不能在普通內(nèi)部類中聲明靜態(tài)變量,否則編輯器會(huì)報(bào)錯(cuò)!?。?!