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 child class can declare a narrower subset of exceptions. ExceptionB extends ExceptionA, so throwing ExceptionB is more restrictive than throwing ExceptionA. This is valid - the child is promising to throw fewer types of exceptions than the parent declared.