You get access to a member from the same class. Member visibility rules apply to classes, not class objects.
To continue, the Java compiler (at compile time) and the Java virtual machine (at run time) apply the visibility rules for the object by first looking at its type.
The compiler performs this action when it has to generate byte code to access the field, call the method, and similar expressions. Access rules are applied based on the qualification type of the object, not just the object. Compiler behavior is determined by the Java language specification.
The Java virtual machine performs this operation during the binding process with the same rules defined by the Language Specification and is explicitly defined by the Virtual Machine Specification.
source share