Here is some simple rules to memorize these access modifiers :
- private: class scope.
- default (or package-private): package scope
- protected: package scope + child (like pakage, but we can subclass it from different pakages). The protected modifier always keeps the “parent-child” relationship.
- public : everywhere.
As a result, if we divide access right into three rights:
- (D)irect (invoke from a method inside the same class)
- (R)eference (invoke a method using a reference to the class, or via “dot” syntax)
- (I)nheritance (via subclassing)
then we have this simple table: