nested class in Java

There are four of types of nested classes in Java:
* A member inner class is a class defined at the same level as instance variables. It is not static. Often, this is just referred to as an inner class without explicitly saying the type.
* A local inner class is defined within a method.
* An anonymous inner class is a special case of a local inner class that does not have a name.
* A static nested class is a static class that is defined at the same level as static variables.

<b>Type of nested classes</b>
| |Member inner class|Local inner class|Anonymous inner class|static nested class|
|-----|-----|-----|-----|-----|
|Access modifiers allowed | public, protected, private, or default access | None. Already local to method. | None. Already local to statement. | public, protected, private, or default access | 
|Can extend any class and any number of interfaces | Yes | Yes| No—must have exactly one superclass or one interface | Yes |
|Can be abstract|Yes|Yes|N/A—because no class definition|Yes|
|Can be final|Yes|Yes|N/A—because no class definition|Yes|
|Can access instance members of enclosing class|Yes|Yes|Yes|No (not directly; requires an instance of the enclosing class)|
|Can access local variables of enclosing class|No|Yes—if final or effectively final|Yes—if final or effectively final|No|
|Can declare static methods|No|No|No|Yes|

A nested class is a member of its enclosing class. Non-static nested classes (inner classes) have access to other members of the enclosing class, even if they are declared private. Static nested classes do not have access to other members of the enclosing class.
```
class OuterClass {
    ...
    static class StaticNestedClass {
        ...
    }
    class InnerClass {
        ...
    }
}
```