Which statement is true about the default constructor of a top-level class?
A. It can take arguments.
B. It has private access modifier in its declaration.
C. It can be overloaded.
D. The default constructor of a subclass always invokes the no-argument constructor of its superclass.
题解
选项 A,预设的构造器不能传入参数。
选项 B,预设的构造器使用的访问权修饰字与其类别的访问修饰字是相同的。
选项 C,预设构造器是当类别中没有明确定义构造器时由编译器自动插入,但如果要达成多载,就必须要在类别中明确定义有参数的构造器。一旦在类别中定义构造器了,这个类别就没有「预设构造器」了,所以「预设构造器」根本不可能会有被多载的情况。
选项 D,预设的构造器预设会去调用上层无参数的构造器。例如 A 类别的预设构造器,自动产生的代码会长得像是以下这样:
public A(){
super();
}
