继承类的含参构造函数注意事项

继承类的含参构造函数注意事项

父类

public class Person {
    public Person(int a){
        System.out.println("Person但构造器");
    }
}

子类

public class Student extends Person{
    public Student(int a){//编译不通过,Person中没有默认的构造函数,隐式super()调用失败,可以显示写super(a);
        System.out.println("Student单构造");

    }
}
posted @ 2021-03-11 19:12  天然卷123  阅读(81)  评论(0)    收藏  举报