It sounds like the code you are describing is something like this:
class A {}
class B extends A {
B() {}
}
There are two sections of the language spec relevant to the question.
Firstly, Section 8.8.7 says that if the constructor body doesn't begin with this(...)
or super(...)
, then it implicitly starts with super()
, an invocation of the superclass' no-arg constructor.
This means B
effectively looks like:
class B extends A {
B() {
super();
}
}
(Try comparing the bytecode with and without the explicit super()
call, you will see they are identical)
For this to compile, A
would have to have a no-arg constructor.
Although it apparently has no constructors, the second relevant bit of the language spec is Section 8.8.9: when no constructors are explicitly declared, a default constructor will be implicitly declared. This has the same access modifier as the class, and take no arguments.
This means A
effectively looks like:
class A {
A() {
super(); // call to superclass constructor because of Sec 8.8.7, that is, Object().
}
}
(Again, try declaring this constructor explicitly and comparing the bytecode)
Such a default constructor is necessary in order for a class to invoke its superclass constructor, in order that the instance is fully initialized before use.