ProgrammingVery hardProduct-company placement · Java

What is printed?

What is printed?
class K {
    static int v = 10 / Integer.parseInt("0");
}
// in main:
try { System.out.print(K.v); }
catch (ArithmeticException e) { System.out.print("AE"); }
catch (ExceptionInInitializerError e) {
    System.out.print("EIIE " + e.getCause().getClass().getSimpleName());
}
  1. A. EIIE ArithmeticException
  2. B. AE
  3. C. EIIE NumberFormatException
  4. D. 0

Correct answer: A. EIIE ArithmeticException

An exception escaping a static initializer is wrapped in ExceptionInInitializerError, whose cause is the original ArithmeticException (division by zero). parseInt("0") itself succeeds.

More OOP with C++ and Java questions

Exams that ask this topic