假设你有一Super
堂课
class Super {
// no constructor
// Java compiler will assign a default constructor
// Super () {}
}
和一Child
堂课
class Child extends Super {
public Child() {
//super(); --> this statement will be inserted by default by Java compiler, even though you don't put it in your code
}
}
如果Super
是这样
class Super {
Super(int a) {
// Now this is the only constructor Super class has
// Java doesn't insert a default constructor now..
}
}
Child
不能没有参数构造函数,因为Super
不再有它
class `Child` {
Child() {
// super();
//this will be error since there is no "no-argument" constructor in Super
}
}