Can someone please tell me what are the difference between static inner class and inner class? I know both can access the outer class private and protected attributes, but what are the difference between 'static' vs 'non-static'?
A non-static one is "connected" to an instance of the outer class; for example, this code works because each Inner instance is connected to an "Outer" instance:
But if you make Inner static, then this doesn't compile. Inner could still access "i" in an Outer object, but there's not an implicit Outer object as there is in this example. In other words, you can create an instance of a static inner class without ever creating an instane of the outer class, but a non-static one requires such an instance.