Multiple choice technology programming languages

Is this code legal ? class ExceptionA extends Exception {} class ExceptionB extends ExceptionA {} class A{ void thrower() throws ExceptionA{ throw new ExceptionA(); } } public class B extends A{ void thrower() throws ExceptionB{ throw new ExceptionB(); } }

  1. yes

  2. no

  3. DO NOT SELECT 1

  4. DO NOT SELECT 2

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

The code IS legal. When overriding a method, Java allows the subclass to narrow the declared exception types - ExceptionB is more specific than ExceptionA (its parent). This follows the principle that subclasses can be more restrictive but not more permissive than the superclass contract.