Witscale Test Center

4.5 Static nested classes. > 4.5.2 Accessibility of variables


4.5.2 Accessibility of variables

Static nested class (like any other static feature of class) has access to only static member variables and static methods of the outer class. It cannot access the instance variables or methods of the enclosing class. Listing 4.4 illustrates how the static-nested class NestedOne can access only the static variables of the enclosing class.

 

 


Error!

Cannot access instance variable

 
NestedOne cannot access outerVar as it is an instance variable. It also cannot access any instance methods of enclosing class OuterOne. As the static nested class does not have the advantage of accessing the instance internals, it is usually defined for the organizational[†††††††] purpose only.