As we all know, the parent class must be constructed before the child class; and if the parent's class constructor takes parameters, then the constructor of the parent class must be called explicitly. My question is, how do you call a parent class constructor that takes parameters explicitly from a child class, if the child class does not have a constructor itself?
public class A {
public String text;
public A(String text) {
this.text = text;
}
}
public class B extends A {
// Now I must call the constructor of A explicitly (other wise I'll get a
// compilation error) but how can I do that without a constructor here?
}
The answer is: you can't!
In case the super class has a parameter free constructor, the compiler can add one like that for you in subclass, too.
But when the super class needs parameters, the compiler has no idea where these should come from.
So: consider adding a no args constructor to the super class, it could invoke the other constructor and pass some sort of default values. Alternatively, you can do the same in the derived class.
And just for the record: there are no Java classes without constructors. It is just that the compiler might create one for you behind the covers. From that point of view, your question does not make much sense.