In the Java language, when the abstract keyword is used to modify a class, the class is called an abstract class. An abstract class is a collection of public attributes of all its subclasses and a class that contains one or more abstract methods. Abstract classes can be seen as further abstractions of classes. In the object-oriented field, abstract classes are mainly used for type hiding.
#Can java abstract classes be inherited?
Abstract classes can be inherited.
Except that abstract classes cannot instantiate objects, other functions of the class still exist. Member variables, member methods and constructors can be accessed in the same way as ordinary classes.
Since abstract classes cannot instantiate objects, abstract classes must be inherited before they can be used. For this reason, it is usually decided during the design stage whether to design an abstract class.
In the object-oriented concept, all objects are described by classes, but conversely, not all classes are used to describe objects. If a class does not contain enough information To describe a specific object, such a class is an abstract class.
The parent class contains common methods of the subclass collection, but because the parent class itself is abstract, these methods cannot be used.
Abstract classes refer to classes that are not allowed to be instantiated; abstract methods are methods without method bodies.
1. An abstract class does not need to include abstract methods. It will not be instantiated anyway. Whether the methods inside are abstract or not has no essential impact.
2. However, a class containing an abstract method must not be instantiated. Otherwise, what should I do when this method is executed?
3. If the subclass is non-abstract, then it must implement the abstract method in the parent class; otherwise, the abstract method it inherits still has no method body and is also an abstract method. At this time, it is the same as " A class containing an abstract method must be an abstract class" is a contradiction.
Recommended learning:Java video tutorial
The above is the detailed content of Can java abstract classes be inherited?. For more information, please follow other related articles on the PHP Chinese website!