I'm reconstructing the following code from a tutorial. When I run complie it I get the following error:
constructor Vierbeiner in class Vierbeiner cannot be applied to given types; required: java.lang.String found: no arguments reason: actual and formal argument lists differ in length
My understanding is that this error occurs because the parent class Vierbeiner has a constructor that requires a String argument and no constructor requiring no argument. What I don't understand is why I get this error without creating an object of class Hund. Why is a constructor being called when I haven't created an object of class Hund? Every existing question I've seen about this error involves creating an object of the child class.
public class Vierbeiner {
public static void main(String[] args){
Vierbeiner hund = new Vierbeiner("Bello");
hund.rennen();
}
String vierbeinerName;
Vierbeiner(String pName) {
vierbeinerName = pName;
}
public void rennen() {
System.out.println(vierbeinerName+" rennt los!");
}
}
class Hund extends Vierbeiner {
}
EDIT: In reponse to the answers I've gotten, what's still not clear to me is why the following (case 1) compiles with no problem:
public class Vierbeiner{
public static void main(String[] args){
Vierbeiner hund = new Vierbeiner();
Hund hund2 = new Hund();
// Hund hund3 = new Hund("doggy");
}
String vierbeinerName;
Vierbeiner() {
vierbeinerName = "test";
};
Vierbeiner(String pName){
}
}
class Hund extends Vierbeiner{
};
In which I create a Hund object seemingly using the no argument constructor which I defined in the Vierbeiner class.
But if I uncomment the following (case 2) I get a compilation error:
Hund hund3 = new Hund("doggy");
In case 1, the compiler looks to the parent class Vierbeiner to find a no argument constructor to create the hund2 object. In case 2 I would expect the compiler to do the same thing, that is go to the parent class Vierbeiner to find a string argument constructor to create the hund3 object, but this doesn't seem to be the case without using "super" and I don't understand why.