class Animal{
String s;
Animal(String s){
this.s = s;
}
}
class Dog extends Animal{
Animal animal;
Dog(String s) {
super(s);
}
//here is an error "Implicit super constructor Animal() is undefined.Must explicitly invoke another constructor"
Dog(Animal animal){
this.animal = animal;
}
}
Run Code Online (Sandbox Code Playgroud)
我的困惑是,我已经调用了超类的构造函数 - 参数
Dog(String s) {
super(s);
}
Run Code Online (Sandbox Code Playgroud)
但为什么我仍然在另一个构造函数狗(动物动物)中得到错误信息?
在这个例子中构造函数机制如何工作?
谢谢!
| 归档时间: |
|
| 查看次数: |
62 次 |
| 最近记录: |