Use a non-static nested class (or inner class) if you require access to an enclosing instance’s non-public fields and methods . Use a static nested class if you don’t require this access.
Read moreHow do you use a class inside a class?
Non-static nested classes are called inner classes. Nested classes that are declared static are called static nested classes. A nested class is a member of its enclosing class. Non-static nested classes (inner classes) have access to other members of the enclosing class, even if they are declared private .
Read moreHow do I access an inner class?
They are accessed using the enclosing class name . To instantiate an inner class, you must first instantiate the outer class. Then, create the inner object within the outer object with this syntax: OuterClass.
Read moreHow do inner classes work?
Inner classes are a security mechanism in Java. We know a class cannot be associated with the access modifier private, but if we have the class as a member of other class, then the inner class can be made private . And this is also used to access the private members of a class.
Read more