3

私はJavaが初めてで、以下の例で混乱しています

public class Test {

   int testOne(){  //member method
       int x=5;
         class inTest  // local class in member method
           {
             void inTestOne(int x){
             System.out.print("x is "+x);
         //  System.out.print("this.x is "+this.x);
           }
  }
       inTest ins=new inTest(); // create an instance of inTest local class (inner class)
       ins.inTestOne(10);
       return 0;
   }
    public static void main(String[] args) {
   Test obj = new Test();
   obj.testOne();
}
}

8 行目の "this" キーワードを使用して inTestOne() メソッドのシャドウ変数にアクセスできない理由

4

2 に答える 2

2

this.メンバーへのアクセスに使用されます。ローカル変数はメンバーではないため、シャドウされている場合はこの方法でアクセスできません。

于 2014-08-25T16:15:26.907 に答える