Types of nested classes
- Eclipse: Oxygen
- Java: 1.8
The types of nested classes are categorized here. Category of the nested class, we have already seen in the inner class and further types will be seen in the forthcoming articles.
In Java, It is possible to specify, a class within another class, such classes are known as nested classes. They allow you to logically group classes that are only used in one place. Therefore, this increases the use of encapsulation and creates a more readable and maintainable code.
Nested classes are divided into two types:
- Nested, non-static classes- Non-static classes are an inner class. We know that a class cannot be associated with the private access modifier, but if we have the class as a member of another class, then the inner class can be made private. And this is also used to access private members of a class.
- Static nested classes −These are members of a class and declared static are called static nested classes. It can be accessed without creating an instance of the external class, using other static members. Like static members, a static nested class does not have access to the instance variables and methods of the external class.
Contributed by: Poonam Tomar