引用:https://www.cnblogs.com/jyroy/p/11152367.html

父类Person
package Person_exdends;

  class Person {
      String name = "未命名";
      int age = -1;

Person(String name, int age) {
    super();
    System.out.println("开始构造方法person(),此时this.name=" + this.name + "  this.age=" + this.age);
    this.name = name;
    this.age = age;
    System.out.println("person()构造完成,此时this.name=" + this.name + "  this.age=" + this.age);
}
  }

子类Student
package Person_exdends;

  class Student extends Person {
      String school = "未定义学校";

Student(String name, int age, String school) {
    super(name, age);
    System.out.println(
            "开始构造方法Student(),此时this.name=" + this.name + "  this.age=" + this.age + " this.school=" + this.school);
    this.school = school;
    System.out.println(
            "Student()构造完成,此时this.name=" + this.name + "  this.age=" + this.age + " this.school=" + this.school);
}
  }

package Person_exdends;

  public class Main {
      public static void main(String[] args) {
          new Student("Tom", 20, "清华");
      }
  }

 posted on 2020-08-09 18:39  魂蛋  阅读(170)  评论(0编辑  收藏  举报