Three modifiers of Java

1.abstract

1. Abstract modified class: can not new objects, but can declare references.
2. Abstract modification method: only method declaration, no method to achieve.
· There is not necessarily an abstract method in the abstract class, but the class of the abstract method must be an abstract class.
· After the subclass inherits the abstract class, you must override all abstract methods of the parent class, otherwise the subclass is still an abstract class.

2.static

1. Static modification attributes (static attributes, class attributes): static attributes are attributes shared by all objects in the entire class. There is only one copy in the entire class. No multiple copies are created due to the creation of multiple objects. You can directly pass the class name. Visit.
2. Static modification method: In this class, it can be directly called by "static method name", in other classes, it can be called by class name. Static method name. Direct access to static members is allowed, and non-static members cannot be accessed directly; this or super keywords cannot be used in static methods.
3. Static code block: static {// code block} When running a class with a static code block, the content of the code block will be executed first, and will only be executed once during the run.

3.final

1. Final modified class (final class): This class cannot be inherited.
2. Final modification method (final method): This method cannot be overwritten.
3. Final modified variable (final variable): The value of this variable cannot be changed (no initial value, only one assignment).
· Instance constant: final data type constant name; no default value is provided, manual assignment is required, assignment timing: display initialization, dynamic code block, construction method (Note: if the instance constant is assigned in the construction method, all construction methods must be guaranteed Can be properly assigned).
· Static constant: static final data type constant name; no default value is provided, the initial value must be manually assigned, and the timing of assignment: explicit initialization, static code block.
Object constants: final modification is the basic data type: value is immutable; final modification is the reference type: address is immutable.

Published 6 original articles · liked 0 · visits 85

Guess you like

Origin blog.csdn.net/ShaoWeiY/article/details/104505919