Abstract definition:
Abstraction is the extraction of common and essential content from many things.
For example: Wolves and dogs are all canine subjects, and the canine family is the abstract concept.
Abstract class:
In Java, a method without a method body can be defined, and the concrete implementation of the method is done by the subclass, which is called an abstract method, and the class containing the abstract method is an abstract class.
The origin of the abstract method:
Many objects have the same function, but the specific content of the function is different, then in the extraction process, only the function definition is extracted, not the functional body, then only the function declaration, the method without functional body is called abstract method.
Characteristics of abstract Classes
Abstract classes and abstract methods must be decorated with the abstract keyword.
Abstract methods have only method declarations, no method bodies, and are defined in abstract classes.
Format: Modifier abstract return value type function name (parameter list);
Abstract classes cannot be instantiated, that is, you cannot create objects with new. The reasons are as follows:
Abstract class is the concrete thing extracted, itself is not specific, there is no corresponding instance. For example: The canine family is an abstract concept that really exists in wolves and dogs.
and abstract classes do not make sense to invoke an abstract method even if an object is created. Job coordinates www.zhizuobiao.com
An abstract class is instantiated by its subclasses, and the subclass needs to overwrite all abstract methods in the abstract class before the object can be created, or the subclass is an abstract class.
Precautions:
Abstract classes do not necessarily contain abstract methods, but classes that contain abstract methods must be declared as abstract classes
If a class is defined as an abstract class, the class cannot create an object
Protecting data in an abstract class
Abstract classes are primarily inherited by other classes and implement their abstract methods
Abstract classes are usually abstractions of similar classes
Similar classes: Classes that have the same properties, different methods
Java abstract class