Java Access Indicator

Source: Internet
Author: User

The Java access indicator poublic,protected and private are placed before a method or data member. Each access indicator only Controls access to that particular definition

Public: classes, generic variables, and methods that are modified with public, and any classes within and outside the package (including subclasses and ordinary classes) can be accessed;

protected: Classes, generic variables, and methods modified with protected, any class within the package, and subclasses of the package that inherit from that class to access

The protected keyword introduces us to a concept called "Inheritance", which builds on existing classes and joins new members in them without affecting existing classes-we call this existing class "base class" or "Basic class" (base classes). Can also change the behavior of existing members of that class. For the inheritance from an existing class, we say that our new class "extended" (extends) the existing class,protected emphasis on inheritance;

default: What happens if you don't specify an access indicator at all? The default access does not have a keyword, but it is often referred to as "friendly" (friendly) access. This means that all other classes within the current package can access "friendly" members, but for all classes outside the package, these members are "private" and inaccessible to outsiders. default Focus Highlight Package ;

Private: The private keyword means that no one can access the member unless that particular class, and from the method of that class, is available. Other members within the same package cannot access private members, which makes them seem to isolate the class from ourselves. On the other hand, it is not possible to create a package from several collaborators. So private allows us to be free to change that member without worrying about whether it affects another class within the same package

Java Access Indicator

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.