Java OCA OCP Practice Question 222

Question

Given:

try { int x = Integer.parseInt("two"); }

Which could be used to create an appropriate catch block? (Choose all that apply.)

  • A. ClassCastException
  • B. IllegalStateException
  • C. NumberFormatException
  • D. IllegalArgumentException
  • E. ExceptionInInitializerError
  • F. ArrayIndexOutOfBoundsException


C and D are correct.

Note

Integer.parseInt can throw a NumberFormatException, and IllegalArgumentException is its superclass (that is, a broader exception).

A, B, E, and F are not in NumberFormatException's class hierarchy.




PreviousNext

Related