Nested class in Java
Nested class in Java Java allows you to define a class inside another class; these are called nested classes. They boost the use of encapsulation and produce more understandable and manageable code by allowing you to logically arrange classes that are only used in one location. A nested class's scope is limited by the enclosing class's scope. As a result, the class NestedClass in the example below does not exist separately from the class OuterClass. The members of the class in which it is nested, including private members, are accessible to a nested class. However, the member of the nested class is not accessible to the enclosing class. A nested class belongs to its encompassing class as well. A nested class may be declared private, public, protected, or package-private (default) as a member of its enclosing class. Nested classes are divided into two categories: static nested class: Nested classes that are declared static are called static nested classes. inner class: An in...