In this example I have a subclass with a blank constructor. In the superclass there is two constructors provided. When I execute the main in the code below, it turns out that it prints "I am the super constructor without parameter." My question is that, why the compiler ignores the blank constructor in the subclass? If I can accept this "ignorance", then I understand that the compiler will execute the default constructor of the subclass, which, in this case, is the one in the superclass with no parameter. Here is the subclass:
package extendisevil;
public class SubConstructorInherit extends ConstructorInherit {
public SubConstructorInherit(String param) {
}
public static void main(String[] args) {
SubConstructorInherit obj = new SubConstructorInherit("valami");
}
}
And here is the super:
package extendisevil;
public class ConstructorInherit {
public ConstructorInherit(String name) {
System.out.println("I am the super constructor with String parameter: " + name);
}
public ConstructorInherit() {
System.out.println("I am the super constructor without parameter.");
}
}
Thank you for your help!