In Java, an abstract method is a method modified with abstract. This method only declares the returned data type, method name and required parameters. There is no method body, which means that the abstract method only needs to be declared. No need to implement. When a method is abstract, it means that the method must be overridden by methods in subclasses.
In Java, an abstract class is a class that cannot be instantiated using the new method, that is, a class that does not have a specific instance object. Abstract classes are somewhat similar to "templates", with the purpose of creating and modifying new classes according to their format. So what are Java abstract methods?
Objects cannot be created directly from abstract classes. New subclasses can only be derived from abstract classes, and then objects can be created by their subclasses. When a class is declared as an abstract class, the modifier abstract is added in front of the class.
Member methods in abstract classes can include general methods and abstract methods.
Abstract method is a method modified with abstract. This method only declares the returned data type, method name and required parameters. There is no method body, which means that the abstract method only needs Declaration without implementation.
When a method is an abstract method, it means that the method must be overridden by the method of the subclass, otherwise the method of the subclass is still abstract, and the subclass must also be abstract. , that is, declared as abstract.
Abstract classes do not necessarily contain abstract methods, but classes containing abstract methods must be declared as abstract classes. The abstract class itself has no actual functions and can only be used to derive its subclasses. Abstract classes can contain constructors, but constructors cannot be declared abstract.
Abstract classes cannot be modified with final, that is, a class cannot be both a final class and an abstract class.
abstract cannot modify the same method in parallel with private, static, final, and native.
The above is the detailed content of What is java abstract method. For more information, please follow other related articles on the PHP Chinese website!