Yes Ademir, you’re completly right.
In Java, all classes extends Object, and every class, before execute its constructor’s code, makes a call to its superclass through the ‘super()’ assignment. So, if you don’t call ‘super()’ inside the subclass’s constructor, the compiler will do it for you implicitly, but it will always decide by using the ‘super()’ with no-args.
In the last post, TShirt class doesn’t declare any constructor, so the compiler defines a default constructor with default ‘super()’ with no-args. However, its superclass (Clothes) doesn’t have a default constructor. So we must declare ‘super(“string goes here”)’ in TShirt’s constructor explicitly or we will get a compiler error.
The right code would be:
—
class Clothes {
Clothes (String s) { }
}
class TShirt extends Clothes {
TShirt() {
super(“explicitly call to superclass”);
}
}
—
Later, I’ll post others Java Challenge.
Keep tuned.
—
Fernando