If a non-static inner class has a member variable that has exactly same name as of its enclosing class then how can we access the member variable of the enclosing class in a method of inner-class? If we write this.x or simply x then it displays the x of inner class both the times.
Hi: If the enclosing class' member variable, say x, is static then it can be referred to in the inner class' method by enclosingclassname.x If the enclosing class' member variable x is not static, then guess, its instance must be used to refer to x. In the following code, both x and y appear in both Outer & Inner. But in Outer, y is static and x is not static. So in inner class, o.x and Outer.y are used to refer to x and y of the Outer class respectively. The variable z appears in Outer only, so it can be referred to as just z in inner class' method.
The output is as follows: x 20 this.x 20 o.x 10 y 20 Outer.y 10 z 10 Hope this helps, Gaja.