read the code which can the method2 access without reference ? //*****************code*************// class A { public int x; public int y; class B{ protected void method1(){}; class C { protected void method2(){} } } } //***********code_end**************// key:the x,y,method1 are the method2 can access without reference;
Hi Gong, Since an inner class can access only the members of enclosing the class, in this case method2 can access only method1 of class B. If you have any other answer, please mail me at pillaiyar72@hotmail.com R.Balasubramanian
Originally posted by james gong: read the code which can the method2 access without reference ? //*****************code*************// class A { public int x; public int y; class B{ protected void method1(){}; class C { protected void method2(){} } } } //***********code_end**************// key:the x,y,method1 are the method2 can access without reference;
James The inner class C can access any of the variables in C or A. All it needs to do is refer to the variable directly. If one of the inner classes hides one of the variables from an enclosig class then you use the syntax OuterClass.this.variable to access it. the code below should illustrate that for you: