🎙 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 6 of 10

What does this print? (code)

What does this print?

public class Main {
    static int f() {
        try {
            return 1;
        } finally {
            System.out.print("F");
        }
    }
    public static void main(String[] args) {
        System.out.println(f());
    }
}
  1. A.1
  2. B.1F
  3. C.F1
  4. D.F
Answer & explanation

Correct answer: F1

finally runs before the method actually returns, so "F" is printed first, then main prints the returned 1.

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 →