Differences between Java modifiers public, private, protected and default

Source: Internet
Author: User

Description of the meanings of the access modifiers public, private, protecte, and default in Java:
Public (interface access permission): modifier with the widest access restriction in Java, which is generally called "public ". Classes, attributes, and Methods Modified by the package can be accessed not only across classes, but also across packages.
Private (you cannot access): the shortest modifier in Java, which is generally called "private ". The classes, attributes, and Methods Modified by the class can only be accessed by the objects of the class. The subclass of the class cannot be accessed, and cross-package access is not allowed.
Protected (inherited access permission): An access modifier between public and private. It is generally called a "protected form ". Classes, attributes, and Methods Modified by the class can only be accessed by methods and subclasses of the class, even if the subclass can be accessed in different packages.
Default (package access permission): it is usually called "default access mode" without any access modifier. In this mode, only access in the same package is allowed.
(Only in 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.