面试题整理3
以下程序执行后显示什么结果
public class Parent {
??public Parent(){
???System.out.println("-----Parent--------");
??}
}
public class Child extends Parent {
?public Child(){
??System.out.println("-------child------");
?}
?Brother b = new Brother();
}
public class Brother {
?public Brother(){
??System.out.println("------brother--------");
?}
}
public class TestChild {
?public static void main(String[] args) {
??System.out.println(new Child());
?}
}
?
------执行结果--------
-----Parent--------
------brother--------
-------child------
test.pro3.Child@6e1408
?
?
-----解释-----
?/**
? * 初始化顺序:
? * 父类变量-》父类构造-》子类变量-》子类构造
? */