26_super

06_super

  1. super
    1. super必须只能出现在子类的方法或子类的构造方法中!
    2. super调用父类构造方法,必须在构造方法的第一个
    3. super和this不能同时调用构造方法!
public class Application {
    public static void main(String[] args) {
        Student student = new Student();
    }
}
public class Person {
    public Person() {
        System.out.println("调用父类构造");
    }
}
public class Student extends Person{
    public Student() {
        super();//隐藏代码,调用父类构造
        System.out.println("调用子类构造");
    }
}
调用父类构造
调用子类构造
posted @ 2024-07-02 21:59  神莹  阅读(30)  评论(0)    收藏  举报