🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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");
        }
    }
}
  1. A.ABD
  2. B.ACD
  3. C.ABCD
  4. 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 →