创建子类的实例时,Java在执行子类构造函数之前会自动调用基类的默认构造函数。
/* from n o w j a v a . c o m - 时 代 Java */ class Ball { public Ball() { System.out.println( "Hello from the Ball constructor"); } } class BaseBall extends Ball { public BaseBall() { System.out.println( "Hello from the BaseBall constructor"); } }