Four kinds of permissions in Java

Source: Internet
Author: User
1. Private Permissions

Private can modify data members, construct methods, method members, and cannot decorate classes (this refers to external classes, regardless of inner classes). Members that are decorated by private can only be used in the class in which they are defined and cannot be called in other classes.

2. Default Permissions

Classes, data members, constructor methods, method members, all have the ability to use the default permissions, that is, no keywords are written. The default permissions are the same as package permissions, and the elements of the same package permission are called only in the class in which they are defined, and in the same package class.

3. Protected rights (Protected)

Protected can modify data members, construct methods, method members, and cannot decorate classes (this refers to external classes, regardless of inner classes). Members that are modified by protected can be called in the class that defines them, in the same class as the package. If classes with different packages want to invoke them, then the class must be a subclass of the class that defines them.

4. Public rights

Public can decorate classes, data members, constructor methods, method members. Members that are modified by public can be called in any class, regardless of the same package or different packages, which is the most privileged modifier.

Four kinds of permissions in Java

Related Article

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.