Types of Inner classes
Based on the place of the class which we defined the interface and the modifier we use inner classes can be categories as follows.
Static Inner classes
As with class methods and variables, a static nested class is associated with its outer class. When working with static inner class we should treat them as the same way we treat other static members of a class. So
- Similar to inner class, but declared asstatic
- No link to an instance of the outer class.
- Can only access static fields and methods of the outer class.
To refer static nested class we can use the outer class name as follows;
OuterClass.nestedClass
For example, to create an object for the static nested class, we can use following syntax:
OuterClass.nestedClass example = new OuterClass.nestedClass( );