What is an abstract class?
The method modified by abstract
is called an abstract method; the class modified by abstract
is called an abstract class.
An abstract class cannot be instantiated because it is not a concrete class, or such a class is not complete enough and cannot directly use the new keyword to call its constructor to generate an object of this class. We can use abstract to define an abstract class and abstract method.
Abstract class instance:
abstract class 类名 { abstract int 方法名(int x,int y); }
Abstract methods have no method body. It should be noted that abstract classes can have both abstract methods and ordinary methods. Note that abstract methods do not have method bodies (that is, there are no curly braces after the methods). All entity subclasses that inherit this abstract class must implement this abstract method.
Characteristics of abstract classes:
(1) Abstract classes cannot be instantiated
(2) Constructors and static methods cannot be abstract
(3) Abstract methods of parent classes are often implemented in subclasses
(4) Abstract classes can have object references pointing to subclass objects
Recommended tutorials:java tutorial
The above is the detailed content of How to understand abstract classes in java. For more information, please follow other related articles on the PHP Chinese website!