package day21; class Person01{ private String name; private int age; // Person01(){} // 父类的无参数的初始化方法(构造方法) // 有参数的构造方法 没有无参数的构造方法 Person01(String name, int age){ super(); // 所有的类必须继承基类 object类 this.name = name; this.age = age; } } // 继承报错 父类没有无参数构造方法 因为子类初始化的时候 父类也必须初始化 class Student01 extends Person01{ private int score; // 子类初始化的时候 主动使用父类的有参数的构造方法 public Student01(String name, int age){ super(name, age); } public Student01(String name, int age, int score){ super(name, age); this.score = score; } } public class ExtendsDemo02 { public static void main(String[] args) { } }