Difference between protected private and public, protectedprivate

Source: Internet
Author: User

Difference between protected private and public, protectedprivate

1. public, protected, and private are used to define the access permissions of members in Java. Another type is "default", that is, no permission modifier is added before a member. For example:
Public class {
Void method (){};
}
Method is the default permission.

The access permissions of these four modifiers are as follows:
-----------------------------------------------
Class, package, subclass, and others
Public allow
Protected allowed not allowed
Allow by default or not
Private: Not allowed. Not allowed.
-----------------------------------------------

 


The Java language defines the six common modifiers public, protected, private, abstract, static, and final.
Five frequently-used modifiers are also defined. The following describes the 11 Java modifiers:
1. public
Objects used: classes, interfaces, and members
Introduction: No matter where the package is defined, this class (interface, member) is accessible.
2. private
Intended audience: Members
Introduction: A member can only be accessed in the class that defines it.
3. static
Object used: Class, method, field, initialization Function
Introduction: an internal class named static is a top-level class, which is irrelevant to the members of the class. Static Method
Is a class method,
Is to be directed to the class rather than the instance of the class. A static field is a class field.
Number of instances.
Only one instance is pointed to the class rather than the instance of the class. The initialization function is executed when the class is loaded.
Instead of creating
Executed when the instance is running.

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.