What is the significance of Inner Classes and Static Inner Classes? or Why are nested classes used?
When a class is defined within another class then such a class is called a nested class.
Inner class is a non static class declared inside another class.Non-static inner class keep the reference of outer class and allow to access member variable of outer class. It helps in defining an interface of a class.
We use nested classes because of the following reasons:
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.
For more information, visit the following links: