The relationship between abstract classes and abstract methods
Classes with abstract methods must be abstract classes; Abstract classes do not necessarily have abstract methods
When subclasses inherit abstract classes, they must all implement (or override) the abstract methods in the abstract class, otherwise the subclasses are still abstract classes
Because subclasses inherit the entire contents of the parent class, it is also equivalent to an abstract method in the subclass, which overrides the abstract method.
Abstract class features: Must have the abstract keyword decoration, can not be created by new object, abstract method can not write function body (non-abstract method must write function body)
Keyword Small summary: Do not want other classes to override the method, with final, content uncertainty method, with abstract (sub-class usage is not the same);
Want to share with static
1 //define an abstract class2 Abstract classstudent{3 //Abstract Methods4 Public Abstract voidstudy ();5 //Non-abstract methods6 Public voidWork () {7SYSTEM.OUT.PRINTLN ("Study hard");8 }9 }Ten classGoodstudentextendsstudent{ One //the abstract method must be implemented, otherwise the class is still an abstract class A Public voidStudy () { -SYSTEM.OUT.PRINTLN ("Good students do not study"); - } the } - Public classTest { - Public Static voidMain (string[] args) { -Goodstudent s=Newgoodstudent (); + //calling the implementation method - s.study (); + //invoke a non-abstract method inherited from an abstract class A s.work (); at } -}
The relationship between the Java abstract class and the abstract method