Home  >  Article  >  Java  >  What do java modifiers modify?

What do java modifiers modify?

(*-*)浩
(*-*)浩Original
2019-11-12 13:28:461974browse

What do java modifiers modify?

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, methods

protected: 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn