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 moreAre inner classes bad?
They’re not “bad” as such . They can be subject to abuse (inner classes of inner classes, for example). As soon as my inner class spans more than a few lines, I prefer to extract it into its own class. It aids readability, and testing in some instances.
Read moreWhat is the point of inner classes?
We use inner classes to logically group classes and interfaces in one place to be more readable and maintainable . Additionally, it can access all the members of the outer class, including private data members and methods.
Read more