Java inner class or nested class is a class which is declared inside the class or interface.
We use inner classes to logically group classes and interfaces in one place so that it can be more readable and maintainable.
Additionally, it can access all the members of outer class including private data members and methods.
There are basically three advantages of inner classes in java. They are as follows:
Inner class is a part of nested class. Non-static nested classes are known as inner classes.
There are two types of nested classes non-static and static nested classes.The non-static nested classes are also known as inner classes.
Non-static nested class (inner class)
Static nested class
|Member Inner Class||A class created within class and outside method.|
|Anonymous Inner Class||A class created for implementing interface or extending class. Its name is decided by the java compiler.|
|Local Inner Class||A class created within method.|
|Static Nested Class||A static class created within class.|
|Nested Interface||An interface created within class or interface.|