The difference between Java protected and default permissions

Source: Internet
Author: User

Scope Current class Same package Descendant class Other Package
Public √ √ √ √
Protected √ √ √ X
Friendly (default) √ √ X X
Private √ X X X

Friendly is the default access permission (the member variable is not public protected and private)
Focus on the difference between protected and fiendly two kinds of permissions: For protected member variables, descendant classes can be accessed anywhere (inside or outside the package), but for friendly or default member variables, there is no descendant class access concept, This means that if the descendant class is within the package, it can be accessed, and the descendant class is not accessible outside the package. Protected can be accessed in its subclasses, regardless of whether they are in a subclass or an instance of a subclass, regardless of which package they are in, but if the subclass is not in the same package as the parent class, and the child class is accessed with an instance of the parent class

The difference between Java protected and default permissions

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.