Java protected and private

Source: Internet
Author: User
When it comes to protected and private, we should analyze it from two aspects.

First, visibility

Protected: Within the package or in the outsourcing of the method belongs to the subclass of the class is visible inside, that is, the class or object within the package can be called by the method of the class object of the method, for the outsourcing of the method belongs to the class inside the child class is said, The subclass of the owning class (which is not in the same package as the parent class) can invoke the method, even if the class is not inside the package, but this subclass inherits the method that cannot be called in other classes (where the package is different from the parent class).

Private: Called only within this class, including the main function

2nd: Inheritance

Protected: Can inherit by quilt class

Private: Cannot inherit from quilt class


Java protected and private

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.