← Quiz: Java Exception Handling: all 10 questions
Quiz: Java Exception Handling · Question 10 of 10
What does this print? (code)
What does this print?
public class Main {
public static void main(String[] args) {
try {
int n = Integer.parseInt("12a");
System.out.println(n);
} catch (NumberFormatException e) {
System.out.println("not a number");
}
}
}
- A.12
- B.0
- C.not a number
- D.Compile error
Answer & explanation
Correct answer: not a number
"12a" is not a valid integer, so parseInt throws NumberFormatException, an unchecked exception.
Can you get the rest right without peeking?
Take the timed Quiz: Java Exception Handling quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →