A function consists of a function definition (return value type, function name, and parameter list) and a function body.
Abstract function: only functions are defined, and no function body is defined using the abstract keyword. For example
abstract void fun();
Cause of error: if one or more abstract functions exist in a class, the class must be defined as an abstract class.
What is an abstract class?
The class defined using abstract is called an abstract class (base class ).
[1] The constructor of the abstract class cannot be called to generate the object of the abstract class.
[2] If a class contains abstract functions, the class must be an abstract class.
[3] A class without abstract functions can also be an abstract class.
Abstract class: used for inheritance. An object can be generated by subclass of an abstract class.
After the subclass inherits the abstract class as the parent class, the abstract function of the abstract class can also be inherited. According to article [2], the subclass must be defined as an abstract class, however, in this case, the object cannot be generated. In addition, you can add the function body through the write-down abstract function, so that the object can be generated.
Abstract class person {person () {system. Out. println ("person constructor");} abstract void eat (); // abstract function, can also be inherited}
Class Chinese extends person {Chinese () {system. out. println ("Chinese constructor");} void eat () {// rewrite system. out. println ("eat with chopsticks ");}}
Class test {public static void main (string ARGs []) {person P = new Chinese (); // converts P. Eat ();}}
Can an abstract class have Constructors ??
Although the constructor of abstract classes cannot be called using new, the constructor of abstract classes can be called using super, so the conclusion is acceptable.
Abstract Functions and abstract classes