Java access modifier

Source: Internet
Author: User

Public: can be accessed by all classes (interfaces, members).

Protected: can only be accessed by classes in this class, in the same package, and if accessed in other packages, it must be a subclass of the class to which the member belongs.

Private: Member variables and methods can only be accessed in the class in which they are defined, and other classes cannot access them. Gets and changes the member variable, generally with get (), set (), public method. Implements the Java object-oriented encapsulation idea.

default modifier : Access rights are similar to protected but are not accessible to subclasses of different packages when decorating class members.

Static: A modified variable, called a class variable or static variable. Static variables exist with the class, and each instance shares this static variable, which is initialized when the class loads.

Final: A variable declared as final must be given an initial value at the time of declaration, and only read in future references cannot be changed. A decorated class cannot be derived from a subclass, and cannot be overridden by methods of the current subclass when the method is decorated.

Abstract: An instance of the abstract class cannot be created. are generally inherited to implement abstract methods. Class has to be defined as abstract, as long as there is an abstract method, but the abstract class is not necessarily protected by the abstract method.

Java access modifier

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.