Wednesday, August 25, 2010

NumberFormatException extends IllegalArgumentException: Calc.java

Courtesy of Sun Web Learning Center


Given:

1. class Calc {
2.   public static void main(String [] args) {
3.     try {
4.       int x = Integer.parseInt("42a");
5.     // insert code here
6.       System.out.print("oops ");
7.     }
8.   }
9. }

Which two, inserted independently at line 5, cause the output to be "oops "? (Choose two.)


A } catch (ClassCastException c) {
B } catch (IllegalStateException c) {
C } catch (NumberFormatException n) {
D } catch (IllegalArgumentException e) {
E } catch (ExceptionInInitializerError e) {

C and D are correct. NumberFormatException extendsIllegalArgumentException.

No comments:

Post a Comment