What is the difference between Java inner class and static nested class?

+1 vote
2,674 views
asked Nov 2, 2017 by Hitesh Garg (799 points)  

What is the difference between an inner class and a static nested class in Java?
Does design / implementation play a role in choosing one of these?
What are the diffferent usage of both of them?

1 Answer

0 votes
answered Jun 9, 2021 by Stella Aldridge (20 points)  

As far as I know, Java allows you to define a class within another class which is called a nested class.
With class methods and variables, a static nested class is associated with its outer class. And like static class methods, a static nested class cannot refer directly to instance variables or methods defined in its enclosing class: it can use them only through an object reference.

...