A table is shown as follows:
Note: Check to make it visible. That is, you can use the class name/object to access the methods and attributes of a specific modifier. You can use this keyword to access methods and attributes in this class (Of course, this cannot be used for code blocks modified by the static keyword ), this keyword can indicate the reference of this class object.
For the protected modifier, note that the attributes and Methods Modified by this keyword are also visible in the subclasses of different packages, this indicates that the subclass inherits the attributes and Methods Modified by protected in the parent class. Instead of using the parent class/parent class object to access the protected-modified attributes or methods in the parent class.
Even if the parent class object is instantiated in the subclass of different packages, it is impossible for the parent class object to access the attributes and Methods Modified by protected. Because it is invisible. As shown in:
Conclusion: it is better to understand the access control modifier in Java with visibility.
Author: Wu xiachi