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

Java allows overriding methods to declare narrower checked exceptions than those declared by the superclass method. Since ExceptionB extends ExceptionA, the subclass method throws a more specific exception, which complies with Java overriding rules and compiles without issue.