The example of this article tells the Java method rewrite, share for everybody for reference. The specific analysis is as follows:
An overview of the methods of rewriting:
1. In subclasses, you can override the methods inherited from the base class as needed.
2, the overridden method and the overridden method must have the same method name, parameter list, and return type.
3, the overriding method cannot use more restrictive access than the overridden method.
Second, the program code is as follows:
Class person{private int age;
private String name;
public void Setage (int age) {this.age = age;
public void SetName (String name) {this.name = name;
public int getage () {return age;
Public String GetName () {return name;
The public String GetInfo () {return ' Name is: ' +name+ ', the age is ' +age;
Class Student extends person{private String school;
public void Setschool (String school) {This.school = school;
Public String Getschool () {return school;
Public String GetInfo () {return ' Name is: ' +getname () + ', Age is ' +getage () + ', School is: ' +school;
} public class testoverride{public static void Main (String args[]) {Student Student = new Student ();
person who = new person ();
Person.setage (1000);
Person.setname ("Lili");
Student.setage (23);
Student.setname ("Vic");
Student.setschool ("Shnu");
System.out.println (Person.getinfo ()); System.out.println (Student.getinfO ());
}
}
The results of the execution are shown in the following illustration:
I hope this article will help you with your Java programming.