Java Access Control)

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.