Home>Article>Java> What are java modifiers?

What are java modifiers?

藏色散人
藏色散人 Original
2019-05-22 14:34:06 11182browse

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.

What are java 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!

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