When the field has no access modifier, it has default visibility.
From the scope of InnerClass#printme()
, a sub class' method, it is accessible. So
i+=10;
is accessing the InnerClass
instance's field, which was initialized to 0.
private
fields are not visible to sub classes, so InnerClass
can't access its own. But because your InnerClass
is an inner class which is within the body of the OuterClass
it can access the enclosing instance's field. So
i+=10;
is accessing the OuterClass
instance's field.