JAVA Abstract class, java Abstract class
Abstract class
Abstract is a modifier
Can be modified, can be modified class
1. When multiple classes have the same functions, but the feature subjects are different, we extract them upwards. Only the feature definitions are extracted.
Abstract class features:
1. abstract methods must be in abstract classes.
2. abstract classes and abstract methods must be modified by abstract keywords.
3. abstract classes cannot be created because it is meaningless to call abstract methods.
4. To use methods in an abstract class, the subclass must overwrite the methods in the abstract class, and then create a subclass object to call
5. Non-abstract methods can be defined in abstract classes. Sometimes we need to convert this class into abstract classes when the object cannot be created by the new keyword.
6. If the subclass only overrides a part of the abstract method, the subclass is still an abstract class. If the abstract class method is to be used, the subclass must override all methods in the abstract class.
It is worth noting that abstract classes are not very different from common classes.
1. An abstract class cannot use the new keyword to create an object.
2. abstract classes can contain abstract methods.
Abstract class Animal {// if the method is abstract, the class must also be abstract. The class must be abstract. The class is abstract, and the method can not abstract void sing (); // abstract method. Remove the braces and use the abstract keyword to modify} class Cat extends Animal {void sing () {System. out. println ("");} class Dog extends Animal {void sing () {System. out. println ("Wang sing") ;}} public class Test {public static void main (String [] args) {Animal c = new Cat (); c. sing ();}}