Multiple choice technology programming languages

When a method is overridden, the overriding method can throw only the same exceptions as the overridden method, a subset of them or subclasses of the exceptions.

  1. True

  2. False

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

When overriding a method, the overriding method cannot throw broader (checked) exceptions than the overridden method. It can throw the same exceptions, a subset, or subclasses of those exceptions, maintaining the contract established by the parent method.

AI explanation

This is a core Java rule for checked exceptions in method overriding. The overriding method's throws clause is restricted to: (a) no exceptions, (b) the same checked exceptions as the overridden method, (c) a subset of those exceptions, or (d) subclasses of those exceptions. It cannot declare new or broader checked exceptions, because that would break the Liskov substitution principle — code calling the superclass method via polymorphism wouldn't be prepared to catch an unexpected checked exception. So the statement is True. "False" would be correct only if overriding methods could freely add unrelated checked exceptions, which the compiler disallows.