Package fifth day; public class Person {public void say () {System.out.println ("I am the Say method for person");}}
The subclass student is as follows:
The fifth day of the package, public class Student extends person{//overrides the parent class's say () method @overridepublic void Say () {System.out.println (" I am student's say Method ");} public static void Main (string[] args) {Student stu=new Student (); Stu.say ();//I am Student say method person p=new Student ();// Polymorphic P.say ();//I am the Say Method of Student}}
the above P.say () can be understood as if the subclass is called by the Say () method, and if the subclass does not have a say () method, then the Say () method of the parent class is called again.
The purpose of inheritance is to extend (meaning that the function of the parent class is not powerful, we can extend the parent class), and thus the code is reused.
Student extends Person
Derived class extension base class------------->> foreign names
Subclass inherits Parent class-->> domestic term
Subclass inherits the parent class, overrides the parent class method, invokes the overridden method when using polymorphism, calls the subclass, or calls the parent class?