In Java, it is possible to define a class within another class, such
classes are known as nested classes. They enable you to logically group
classes that are only used in one place, thus this increases the use of
encapsulation, and creates more readable and maintainable code.
Class Animal {
static class Mammal {
// static and non-static members of Mammal
}
// members of Animal
}
A regular nested class cannot access members of its outer class. But a nested class marked as an inner class can.
OuterClass.NestedClass obj = new OuterClass.NestedClass();