The Java language defines the public, protected, Private, abstract, static, and final modifiers and defines four infrequently used modifiers, the following is an introduction to these 10 Java modifiers:
1. Public
Target objects: classes, interfaces, and members.
Introduction: No matter where the package is defined, the class (interface and member) is accessible.
2. Private
Intended audience: Members.
Description: A member can only be accessed in the class that defines it.
3. Static
Applicable objects: classes, methods, variables, and initialization functions.
Description: The internal class of static rhetoric is a top-level class, which is irrelevant to the members of the class. Static methods are class methods and are directed to the class rather than the instance of the class. A static variable is a class variable. No matter how many instances are created for the class where the variable is located, this variable only has one instance that is directed to the class rather than the class instance. The initialization function is executed when the class is loaded, rather than when the instance is created.
4. Final
Applicable objects: classes, methods, and variables.
Description: classes defined as final are not allowed to have child classes and cannot be overwritten (not used for dynamic queries). Variable values cannot be modified.
5. Abstract
Target objects: classes, interfaces, and methods.
Description: abstract classes include methods that are not implemented and cannot be instantiated. The method body of the abstract method is empty. The implementation of this method is defined in the subclass and the class containing an abstract method must be an abstract class.
6. Protected
Intended audience: Members.
Description: A protect member can only be accessed in the package that defines it. If it is accessed in another package, the class implementing this method must be a subclass of the class to which the member belongs.
7. Native
Intended audience: Members.
Description: it is related to the operating platform. Its method is not defined when it is defined. The method is implemented by an external library.
8. Synchronized
Intended audience: methods.
Introduction: For a static method, JVM locks the class where it is located before execution. For a non-static method, a specific object instance is locked before execution.
9. Volatile
Target object: variable.
Introduction: because asynchronous threads can access variables, some optimization operations cannot be used on variables. Volatile can sometimes replace synchronized.
10. Transient
Target object: variable.
Description: variables are not part of the object's persistent State and should not be concatenated with objects.