In object-oriented concepts, all objects are depicted by classes, but conversely, not all classes are used to depict objects, and if a class does not contain enough information to depict a specific object, such a class is an abstract class.
Abstract classes In addition to the object cannot be instantiated, other functions of the class still exist, member variables, member methods and construction methods are accessed in the same way as the normal class.
Because an abstract class cannot instantiate an object, an abstract class must be inherited in order to be used. For this reason, it is often decided at the design stage to not design abstract classes.
The parent class contains a common method for the collection of subclasses, but because the parent class itself is abstract, these methods cannot be used.
To define an abstract class:
Abstract methods
If you want to design a class that contains a special member method whose implementation is determined by its subclasses, you can declare the method as an abstract method in the parent class.
The abstract keyword can also be used to declare an abstraction method, which contains only one method name and no method body.
Abstract methods are not defined, followed by a semicolon, not a curly brace, directly following the method name.
Places of special attention:
- If a class contains an abstract method, the class must be an abstract class.
- Any subclass must override the abstract method of the parent class, or declare itself an abstract class.
Subclasses that inherit an abstract method must overload the method. Otherwise, the subclass must also be declared as an abstract class. Eventually, a subclass must implement the abstract method, otherwise, from the original parent class to the final subclass, it cannot be used to instantiate the object.
Object-Oriented---Java abstract class