Bird
0
0

What will be the output of this Java program?

medium📝 Predict Output Q5 of 15
Java - Exception Handling

What will be the output of this Java program?

public class Demo {
    public static void main(String[] args) {
        try {
            int a = 5 / 0;
        } catch (ArithmeticException e) {
            System.out.print("Catch-");
        } finally {
            System.out.print("Finally");
        }
    }
}
ACatch
BFinally
CCatch-Finally
DRuntime Error
Step-by-Step Solution
Solution:
  1. Step 1: Identify exception thrown in try block

    Division by zero throws ArithmeticException, caught by catch block.
  2. Step 2: Execute catch and finally blocks

    Catch prints "Catch-" and finally prints "Finally".
  3. Final Answer:

    Catch-Finally -> Option C
  4. Quick Check:

    catch and finally both run on exception [OK]
Quick Trick: catch runs on exception, finally always runs [OK]
Common Mistakes:
  • Expecting only finally output
  • Assuming program crashes without catch
  • Ignoring catch block output

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes