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

When overriding a method, the subclass can narrow the declared exception types. ExceptionB is a subclass of ExceptionA, so throwing ExceptionB is compatible with the parent's throws ExceptionA clause. This is legal overriding.