← 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());
}
}
- A.1
- B.1F
- C.F1
- 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 →