An advantage of Inner Class
- Eclipse: Oxygen
- Java: 1.8
This tutorial depicts the Advantage of Inner Class as we have discussed so far in this series of tutorials. Inner classes are the concept where we want to add more encapsulation to the given code. When we declare a class within a class, the inner class can access all the private members, in addition to the inner class, it can hide from the outside world.
An advantage of inner classes
In Java, there are three advantages of inner classes. They are as follows:
- The inner class could be used only by outer class. Inner classes represent a special type of relationship that allows access to all members (data members and methods) of the outer class, including the private class.
- Inner classes are used to develop a more readable and maintainable code because they logically group classes and interfaces in one place.
- Easy access, as the inner object, is implicitly available inside an outer Code optimization requires less code to write. It can avoid having a separate class.