Home > Java > Javagetting Started > What do java modifiers modify?

What do java modifiers modify?

(*-*)浩
Release: 2019-11-12 13:28:46
Original
2052 people have browsed it

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) {
   // 方法体
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Latest Issues
Install JAVA
From 1970-01-01 08:00:00
0
0
0
Unable to install java
From 1970-01-01 08:00:00
0
0
0
Can java be used as the backend of the web?
From 1970-01-01 08:00:00
0
0
0
Is this in Java language?
From 1970-01-01 08:00:00
0
0
0
Help: JAVA encrypted data PHP decryption
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template