Multiple choice technology programming languages

Given: 11.classA { 12. public void process() { System.out.print(”A “); } } 13. class B extends A { 14. public void process() throws RuntimeException { 15. super.process(); 16. if (true) throw new RuntimeException(); 17. System.out.print(“B”); }} 18. public static void main(String[] args) { 19. try { ((A)new B()).process(); } 20. catch (Exception e) { System.out.print(”Exception “); } 21. } What is the result?

  1. Exception

  2. A Exception

  3. A Exception B

  4. A B Exception

  5. Compilation fails because of an error in line 14.

  6. Compilation fails because of an error in line 19.

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

The code uses polymorphism to call B's process method. It runs super.process() to print 'A ', then throws a RuntimeException which is caught in main and prints 'Exception '. Unreachable code compile errors do not trigger for statements after an if(true) throw statement.