Java Programming thought Learning (iv) Access rights

Source: Internet
Author: User
Tags modifiers
Several access rights modifiers

public,protected,private,friendly (there is no such modifier in Java, that is, the package access permission, no access modifiers are provided)

When used, it is placed before the definition of a member (domain or method) in a class, and only controls the access rights of the specific definition it modifies.

Package access rights

is the default access permission, without any keywords

All other classes in the same package have access to this member, and for all other classes outside the package, there is no access permission.

The way to access access to a member is as follows:

  1. Decorate members with public, anyone with access rights anywhere
  2. Do not add access modifiers and place other classes inside the same package
  3. Inherited, inherited classes can access the public and protected members of the parent class
  4. Provides get and set methods to read and change values (the basic principle of JavaBeans)
Public: Interface access rights

It's accessible to everyone.

Private: Unable to access

In addition to the class that contains the member, no other class can access the member

Protected: Inheriting access rights

The protected members of a base class can be accessed only by derived classes (other classes within the same package are also accessible)

Java Programming thought Learning (iv) Access rights

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.