本帖最后由 sam9204 于 2014-6-10 22:45 编辑
下面是People和Child类的定义和构造方法,每个构造方法都输出编号。在执行new Child("mike")的时候都有哪些构造方法被顺序调用输出结果是什么? class People { String name; public People() { System.out.print(1); } public People(String name) { System.out.print(2); this.name = name; } } class Child extends People { People father = new People(); static People f2 = new People("1"); public Child(String name) { System.out.print(3); this.name = name; father = new People(name + ":F"); } public Child(){ System.out.print(4); } } 最后输出结果是:21132。但不知其所以然,请高手帮我分析一下具体的对象初始化顺序,谢谢。修正了一下答案应该是21132 |