We call the class modified with the keyword abstract as an abstract class , that is, an abstract class , for example:
abstractclassA{…}
We call methods modified with the keyword abstract as abstract methods , that is, abstract methods , for example:
abstract int max(int x,int y);
Notice:
1) For abstract methods, only declaration is allowed, and implementation is not allowed, that is, there is no method body, and final and abstract are not allowed to be used to modify a method or class at the same time, and static is not allowed to modify the abstract method, that is, the abstract method must be an instance method.
2) Abstract classes can have abstract methods or non-abstract methods, but non-abstract classes cannot have abstract methods.
For example: the max() method in class A is an abstract method, and the min() method is a normal method (non-abstract method).
abstractclassA{abstractintmax(intx,inty);intmin(intx,inty){returnx<y?x:y;}}
For abstract classes, you cannot use the new operator to create objects of this class. If a non-abstract class is a subclass of an abstract class, then it must override the abstract method of the parent class and give the method body. This means that it cannot The reason why it is allowed to use final and abstract to modify a method or class at the same time.
We can use the abstract class to declare an object. Although the object cannot be created using the new operator, the object can become an upcast object of its subclass object, so that the object can call the method overridden by the subclass.
Note: An abstract class may not have an abstract method. If an abstract class is a subclass of the abstract class, it can either override the abstract method of the parent class or inherit the abstract method of the parent class.