Abstract modifier, which can be used to modify classes and Methods
1. Abstract modifier class will make this class an abstract class. This class will not generate an object instance, but it can be used as the type of object variable Declaration, that is, the compile-time type, abstract classes are like a class of semi-finished products, which must inherit and overwrite the abstract methods.
2. Abstract modifier will make this method become an abstract method, that is, only declarations (definitions) are not implemented, and the Implementation part is replaced. Subclass inheritance is required (overwrite ).
Note: classes with abstract methods must be abstract classes. However, not all abstract methods are abstract methods, but also specific methods.
The abstract modifier must be placed before the class name.
Abstract modification requires that its subclass overwrite (implement. You can call the method after the subclass overwrites (implement) in a multi-state manner. That is to say, the abstract method must be implemented in its subclass unless the subclass itself is also an abstract class.
Note: If the parent class is an abstract class with an abstract method, the subclass inherits the parent class and implements (overwrites) All the abstract methods in the parent class, A subclass can create an instance of an object. Otherwise, the subclass must be an abstract class. Abstract classes can have constructor methods, which are the constructor of the parent class (abstract class) that a subclass needs to call when constructing a subclass object.
In a simple example, there is an abstract class.
Abstract class E {
Public abstract void show (); // public abstract can be omitted
}
Then, if other classes inherit from it, they usually implement the methods in it.
Class F extends E {
Void show (){
// Write the specific implementation code
}
}
Then define a parent class reference pointing to a subclass object in the main method to cause polymorphism, such
E = new F ();
E. Show ();
Actually, the show () method in the subclass is called.