读书人

面试题拾掇3

发布时间: 2012-11-07 09:56:10 作者: rapoo

面试题整理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

?

?

-----解释-----

?/**
? * 初始化顺序:
? * 父类变量-》父类构造-》子类变量-》子类构造
? */

读书人网 >编程

热点推荐