Home > Java > javaTutorial > body text

Discuss those modifiers in Java language

高洛峰
Release: 2017-01-24 15:28:52
Original
1521 people have browsed it

1. Some modifiers provided in java, these modifiers can modify classes, variables and methods. Common modifiers in java are: abstract (abstract), static (static), public (public) ), protected (protected), private (private), synchronized (synchronized), native (local), transient (temporary), volatile (volatile), final (immutable)

2. The modifiers that modify the top-level class include abstract, public, and final, while static, protected, and private cannot modify the top-level class. Member methods and member variables can have multiple modifiers, while local variables can only be modified with final

Accessible scope of three.4 access levels

Discuss those modifiers in Java language

Note: Top-level classes can only be modified by default modifiers and public, and cannot be modified by private and protected

4. The abstract modifier can be used to modify classes and member methods

1. Modify with abstract The class represents an abstract class, and abstract classes cannot be instantiated

2. Use abstract-modified methods to represent abstract methods. Abstract methods have no method body: "{}", used for subclass rewriting

3.In classes modified by abstract, that is, abstract classes can have ordinary methods and abstract methods.

4. Abstract classes and abstract methods cannot be modified by the final modifier. abstract modifier and final modifier cannot be used together

5.Final modifier

1.final means "immutable", it can modify non-abstract classes, non-abstract member methods and Variables

2. Classes modified with final cannot be inherited and have no subclasses

3. Methods modified with final cannot be overridden by methods of subclasses

4.Use final The modified variable represents a constant, such as (PI), so it can only be assigned once and cannot be changed

6. static modifier

1. Member variables modified with static represent static variables, Can be directly accessed through the class name

2. Use static modified member methods to represent static methods, and can be directly accessed through the class name

3. Use static modified programs to send code blocks, when java virtual The full name of machine (JVM) is: Java Virtual Machine can locate them in the method of the runtime data area according to the class name, and it can only be run once.

The above is the Java language introduced by the editor. Those modifiers, I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank you all for your support of the PHP Chinese website!

For more articles discussing the modifiers in the Java language, please pay attention to 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!