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

This is a duplicate of question 149712. The catch blocks are in the wrong order: the parent ExceptionA is caught before the child ExceptionB, making the ExceptionB handler unreachable. This violates Java's exception handling rules and causes a compilation error.