1,默认构造器
默认构造器是没有形式参数的——它的作用是创建一个“默认对象”。如果你写的类中没有构造器,则编译器会自动帮你创建一个默认构造器。如果已经定义了一个构造器(无论是否有参数),编译器就不会帮你自动创建默认构造器。
2,初始化基类
在构造器中调用基类构造器来执行初始化,而基类构造器具有执行基类初始化所需要的所有知识和能力。Java会自动在导出类的构造器中插入对基类构造器的调用。如果基类没有默认基类构造器,或者想调用一个带参数的基类构造器,就必须用关键字super显示地编写调用基类构造器的语句,并且配以适当的参数列表(P130.Java编程思想)。
class Game() {
Game(int i) {
print("i")
}
}
class BoardGame extends Game {
BoardGame(int i) {
super(i);
print("i")
}
}