Java modifiers are used to modify the access restrictions or type restrictions of classes, variables, and methods. They mainly include the following: public, protected, private, default, static, final, abstract, transient, and volatile. The first four are is the access qualification modifier, and the last few are type qualification modifiers.
The Java language provides many modifiers, which are mainly divided into the following two categories:
Access modifiers
Non-access modifier
java modifier is used to define classes, methods or variables, usually placed at the front of the statement.
Access control modifier
In Java, you can use access control modifiers to protect access to classes, variables, methods, and constructors. Java supports 4 different access rights.
default (i.e. default, write nothing): Visible in the same package, no modifiers are used. Use objects: classes, interfaces, variables, methods.
private : Visible within the same class. Use objects: variables, methods. Note: Classes (external classes) cannot be modified
public: visible to all classes. Used objects: classes, interfaces, variables, methods
protected: Visible to classes and all subclasses in the same package. Use objects: variables, methods. Note: Classes (external classes) cannot be modified.
The above is the detailed content of What are java modifiers?. For more information, please follow other related articles on the PHP Chinese website!