← Quiz: Java Exception Handling: all 10 questions
Quiz: Java Exception Handling · Question 1 of 10
What does this print? (code)
What does this print?
public class Main {
public static void main(String[] args) {
try {
System.out.print("A");
int x = 5 / 0;
System.out.print("B");
} catch (ArithmeticException e) {
System.out.print("C");
} finally {
System.out.print("D");
}
}
}
- A.ABD
- B.ACD
- C.ABCD
- D.AD
Answer & explanation
Correct answer: ACD
"A" prints, 5 / 0 throws, the catch prints "C", and finally prints "D". "B" is skipped.
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 →