Explore those modifiers in the Java language

I Some modifiers provided in Java can modify classes, variables and methods. Common modifiers in Java include abstract, static, public, protected, private, synchronized, native, transient, volatile, and final

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

3、 Accessible range of 4 access levels

Note: top level classes can only be modified by default modifiers and public, not private and protected

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

1. An abstract modified class represents an abstract class, which cannot be instantiated

2. Use the abstract modified method to represent the abstract method. The abstract method has no method body: "{}", which is used for subclass rewriting

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

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

V Final modifier

1. Final means "immutable". It can modify non abstract classes, non Abstract member methods and variables

2. The class decorated with final cannot be inherited and has no subclasses

3. Methods modified with final cannot be overridden by subclass methods

4. Variables decorated with final represent constants, such as (PI), so they can only be assigned once and cannot be changed

Vi Static modifier

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

2. The static method is represented by the static modified member method, which can be accessed directly through the class name

3. Send code blocks with static modified programs. When the full name of Java virtual machine (JVM) is: Java virtual machine can locate them in the methods of the runtime data area according to the class name, and can only run once

The above are the modifiers in the Java language introduced by Xiaobian. I hope it will be helpful to you. If you have any questions, please leave me a message, and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>