Java初始化构造函数的顺序

先祖先,再客人,最后自己

class Person{
    public Person(){
        System.out.println("Person");
    }
}

class School{
    public School(){
        System.out.println("School");
    }
}

class Student extends Person{
    School school = new School();
    
    public Student(){
        System.out.println("Student");
    }
}


Student student = new Student();
//执行顺序为Person>School>Student

Person
School
Student

posted @ 2018-05-07 22:19  话少心在  阅读(500)  评论(0编辑  收藏  举报