In this recipe, you will learn about three types of inner classes:
- Inner class: This is a class defined inside another (enclosing) class. Its accessibility from outside the enclosing class is regulated by the public, protected, and private access modifiers. An inner class can access the private members of the enclosing class, and the enclosing class can access the private members of its inner class, but a private inner class or private members of a non-private inner class cannot be accessed from outside the enclosing class.
- Method-local inner class: This is a class defined inside a method. Its accessibility is restricted to within the method.
- Anonymous inner class: This is a class without a declared name that's defined during object instantiation based on the interface only or the extended class.