|
Static nested classes are sometimes referred as top-level nested classes. They are defined within another class yet they are called as “top-level” nested classes because they can be accessed without the instance of the outer class. They are declared inside a class as any static member of that class should be:
class OuterOne {
static class NestedOne {
}
}
NestedOne is just like any other top-level class with one difference. You need to refer it using the enclosing class name as OuterOne.NestedOne. Since this class is a static member of OuterOne, therefore it can be accessed like any other static feature of that class. Therefore you need not create an instance of OuterOne to access the static nested class, NestedOne.
|
|
Static nested classes are sometimes incorrectly referred as static inner classes. However, they are not inner classes by definition. Inner classes are closely associated with an instance of a class whereas the static nested class has nothing to do with the instance of enclosing class. |