Why it is not required to declare the exceptions declared in the superclass' method when overriding it?
--
An implementation of a overriding method in a subclass may be totally different with its overridden method in the superclass. It may not have any exceptions needed to throw at all. The only restriction in Java compiler (8.4.6 Method Throws)is that the overriding method in subclass cannot be declared to throw border or new checked exceptions than the overridden method in the superclass (otherwise, you may break other codes because the runtime polymorphism).
An implementation of a overriding method in a subclass may be totally different with its overridden method in the superclass. It may not have any exceptions needed to throw at all. The only restriction in Java compiler (8.4.6 Method Throws)is that the overriding method in subclass cannot be declared to throw border or new checked exceptions than the overridden method in the superclass (otherwise, you may break other codes because the runtime polymorphism).
Comments
Post a Comment