Multiple choice technology programming languages

Is this code legal ? class ExceptionA extends Exception {} class ExceptionB extends ExceptionA {} public class Test{ void thrower() throws ExceptionB{ throw new ExceptionB(); } public static void main(String[] args){ Test t = new Test(); try{t.thrower();} catch(ExceptionA e) {} catch(ExceptionB e) {} } }

  1. yes

  2. no

  3. DO NOT SELECT 1

  4. DO NOT SELECT 2

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

The catch block order violates Java's rule: more specific exceptions must be caught before their parent types. ExceptionB is a subclass of ExceptionA, so catching ExceptionA first makes the ExceptionB handler unreachable code. This causes a compilation error.