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.