一道筆試題的故事
package architect;
/*
* to constrcut Parent.
to construct Delegatee.
to construct Child.
構造一個類時繁扎,它的父類和成員變量所屬類的構造函數(shù)都會被自動執(zhí)行,
具體順序時先Parent 再 Delegatee 最后child
page 305 軟件架構設計 溫昱
*/
public class ParantChildDelegatee {
public ParantChildDelegatee() {
// TODO Auto-generated constructor stub
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Child child = new Child();
}
}
class Parent {
Parent() {
System.out.println("to constrcut Parent.");
}
}
class Child extends Parent {
Child() {
System.out.println("to construct Child.");
}
Delegatee delegatee = new Delegatee();
}
class Delegatee {
Delegatee() {
System.out.println("to construct Delegatee.");
}
}