The Java language provides many modifiers, which are mainly divided into the following two categories:
Access modifiers (recommended Study: java course)
Non-access modifier
Modifier is used to modify a class, method or variable, usually placed The beginning of the statement. We use the following example to illustrate:
public class ClassName { // ... } private boolean myFlag; static final double weeks = 9.5; protected static final int BOXWIDTH = 42; public static void main(String[] arguments) { // 方法体 }
Access control modifier
##In Java, you can use access control modifiers to protect classes, Access to variables, methods and constructors. Java supports 4 different access rights.
default (i.e. default, write nothing): Visible within 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, methodsprotected: Visible to classes and all subclasses in the same package. Use objects: variables, methods. Note: Classes (external classes) cannot be modified.Non-access modifier
In order to achieve some other functions, Java also provides many non-access modifiers.
static modifier, used to modify class methods and class variables. The final modifier is used to modify classes, methods and variables. Classes modified by final cannot be inherited, modified methods cannot be redefined by inherited classes, and modified variables are constants and cannot be modified. abstract modifier, used to create abstract classes and abstract methods. synchronized and volatile modifiers are mainly used for thread programming.The above is the detailed content of What do java modifiers modify?. For more information, please follow other related articles on the PHP Chinese website!