While doing Dan's mock exam I came across this question:
class A {
A() throws Exception {} // 1
}
class B extends A {
B() throws Exception {} // 2
}
class C extends A {} // 3
Which of the following statements are true?
a. Compiler error at 1.
b. Compiler error at 2.
c. Compiler error at 3.
d. None of the Above
ANS: c
I answered
d thinking that since an overriding method does not need to declare any throws clause(even if the overridden method has one), then it must be the same for constructors.
I understand that constructors are not like methods, and the JLS did specified that
JLS 8.8.7
A default constructor has no throws clause.
It follows that if the nullary constructor of the superclass has a throws clause, then a compile-time error will occur.
But so far, I don't see any reason why the rules have to be any different for constructors? Why does the rule "may not be declared to throw more checked exceptions" not applicable to constructors?
Thanks.