為什么不能加this
//外部類
public class SOuter {
?private int a=99;//外部類的私有變量
? static int b=11;//外部類靜態變量
?//靜態內部類
? public static class SIuter{
?int ?b=22;//內部類的變量
?public void test(){
?System.out.println("訪問外部類中的b;"+SOuter.this.b);
?System.out.println("訪問內部類中的b:"+b);
?}
? }
? //測試靜態內部類
? public static void main(String [] args){
?//直接創建內部類對象
?SIuter si=new SIuter();
?//調用test方法
?si.test();
? }
}
2017-08-12
都是靜態變量,雖然名字相同但是不需要加this。
2017-08-12
外部類中的b是static,因此不需要Outer.this.b
2017-08-12
您好,我的理解是因為你的b已經是外部類的靜態變量.而this是不能在靜態方法中出現的;