We cannot instantiate an inner class within a static context of the outer class, but when we declare this inner class as package- private. we are able to access its constructor. But how ? what is the magic of the constructors ? Are they bounded to the objects or classes ?
static, nested classes) are bound to instances of the outer class.staticnested classes are not bound to an instance of the object. See the official java tutorial atdocs.oracle.com.Innerin:class Outer { class Inner {}}secretly adds to all the constructors ofInnera parameterOuter this$outer, which javac fills in for you if anythisexists to do that with. If you don't understand any of this, that's.. common and this is rather advanced and confusing java. The solution to just opt out of all this confusion and complexity is very simple: Always declare ALL your inner classes asstaticno matter what. Or, of course, learn the trickiness of java's inner classes mechanics.