Bowl(1)
Bowl(2)
Table()
f(1)
Bowl(4)
Bowl(5)
Bowl(3)
Cupboard()
f(2)
Creating new Cupboard() in main
Bowl(4)
Bowl(5)
Bowl(3)
Cupboard()
f(2)
Creating new Cupboard() in main
Bowl(4)
Bowl(5)
Bowl(3)
Cupboard()
f(2)
f2(1)
f3(1)
我的答案也不对,以前看过这方面的知识点,但又忘了被静态修饰时只在类被加裁时执行一次,只后不会再被执行。
如果在能混合进重载和继承就更为经典了.我就借这个发个构造函数重载的,大家也分析下:
class Cake{
Cake(){System.out.println("Cake()");}
}
class Meal {
Meal() { System.out.println("Meal()"); }
}
class Bread {
Bread() { System.out.println("Bread()"); }
}
class Cheese {
Cheese() { System.out.println("Cheese()"); }
}
class Lettuce {
Lettuce() { System.out.println("Lettuce()"); }
}
class Lunch extends Meal {
Lunch() { System.out.println("Lunch()"); }
}
class PortableLunch extends Lunch {
private Cake a=new Cake();
PortableLunch() { System.out.println("PortableLunch()");}
}
public class OverLoadTest extends PortableLunch
{
private Bread b = new Bread();
private Cheese c = new Cheese();
private Lettuce l = new Lettuce();
public OverLoadTest() {
System.out.println("Sandwich()");
}
public static void main(String[] args) {
new OverLoadTest();
}
}
|