Nested classes are divided into two categories:
- static. They are simply called static nested classes.
- non-static. They are called inner classes.
Reasons for using nested classes:
- It is a way of logically grouping classes that are only used in one place.
- It increases encapsulation.
- Nested classes can lead to more readable and maintainable code.
Notes
- Access modifiers (private/public/protected) have no effect on inner classes - independant of the modifier, the classes are public.
- Inner classes could access members of outer class, no meter of their access modifier.