Card 74 / 76: Which of the following code fragments will throw a NumberFormatException?
A)
Integer.parseInt("INVALID");
B)
int e = (2 / 0);
C)
Object x = new Float("1.0"); Double d = (Double) x;
D)
String s = null; int i = s.length();
Answer:
A) Integer.parseInt("INVALID");
Previous Card | ← Previous Card Button |
Next Card | → Next Card Button |
Flip Card | Space-Bar |
B, C, and D are incorrect.
B is incorrect because evaluation of the statement causes an ArithmeticException to be thrown.
C is incorrect because evaluation of the statement causes a ClassCastException to be thrown.
D is incorrect because evaluation of the statement causes a NullPointerExeption to be thrown.
|