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

Java requires catch blocks to be ordered from most specific to most general. ExceptionB extends ExceptionA, so ExceptionB is more specific. Catching ExceptionA first would make the ExceptionB catch unreachable since any ExceptionB would already be caught by ExceptionA. This causes a compilation error.