当超类只有一个带参数的构造函数时,所有带有参数的子类的构造函数都需要super(args)吗?

bru*_*uce 3 java

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)

但为什么我仍然在另一个构造函数狗(动物动物)中得到错误信息?

在这个例子中构造函数机制如何工作?

谢谢!

Gho*_*ica 5

你的问题的答案很简单:是的.

任何子类构造函数必须首先调用super.如果超类只有一个ctor采用一些参数,那么子类中的那些"超级调用"必须使用该ctor.