Access modifiers, Java

Source: Internet
Author: User
Tags modifiers

Access modifiers
There are four access rights in Java, and when different access rights are used, the modified content has different access rights, and the following table describes the ability to access different permissions:

Public protected Default Private

√√√√ in the same class

In the same package (subclass and unrelated classes) √√√

Sub-class √√ of different packages

Unrelated classes in different packages Yes


summarize: In the daily development process, write the class, method, member variable access
To be accessible only in this class , use the private modifier;
The classes in This package can be accessed without modifiers ;
To make the class in this package accessible to subclasses in other packages using the protected adornment
All The classes in the package can be accessed using the public adornment.
Note: If the class is decorated with public, the class name must be the same as the file name. There can be only one public-decorated class in a file.

Access modifiers, Java

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.