abstract modifiers that can modify classes and methods
1. Abstract modifier class, will make this class an abstract class, this class will not be able to generate object instances, but can be used as a type declared by object variables, that is, compile-time types, abstract classes are like semi-finished products of a class, which need to be inherited by subclasses and overwrite the abstract methods.
2. The abstract modification method will make this method an abstract method, that is, there is only a declaration (definition) without implementation, and the implementation part is "; instead. Requires subclass inheritance implementation (override).
Note: A class with an abstract method must be an abstract class. However, abstract classes are not necessarily all abstract methods, but can also be concrete methods.
abstractmodifiers must be placed in the class name when modifying the class.
The abstract modification method requires its subclasses to override (implement) this method. The subclass can be called polymorphically to override (implemented) the method, that is, the abstract method must be implemented in its subclass, unless the subclass itself is also an abstract class.
Note: The parent class is an abstract class, and there are abstract methods in it, so the subclass inherits the parent class and implements (overrides) all the abstract methods in the parent class, so that the subclass has the ability to create instances of objects, otherwise the subclass must also be an abstract class. There can be construction methods in abstract classes, which are the construction methods of the parent class (abstract class) that the subclass needs to call when constructing the subclass object. Here's a simple example of an abstract class abstract class E{ public abstract void show(); public abstract can be omitted
} Then other classes if they inherit it are usually to implement the methods in it class F extends E{ void show(){ Write code for specific implementations
}
} Finally, if a parent reference is defined in the main method to point to a child object, polymorphism will occur, such as E e=new F(); e.show(); The show() method in the subclass is actually called
|