1 Public classPerson {2 3 //Method4 5 Public voidEat () {//define how to eat6 7System.out.println ("Defines the parent class person."));8 }9 Ten Public voidWork () {//define how the parent class works One ASystem.out.println ("Define the parent class person."); - } - the}
Public classChildextendsperson{ Public voidWork () {//methods for defining sub-class workSystem.out.println ("Sub-class child does not love work"); } Public Static voidMain (string[] args) { person child=NewChild ();//Child class Person class, to upward transformationchild.work (); Child.eat (); }
Subclass child does not love to work
Defines the parent class person. How to eat
1.20, create a parent class, create three methods in the parent class, override the third method in the subclass, create an object for the subclass, transform it upward to the base class, and call this method.