Question:

What will be the output of the following Java code?

public class Test {
 public static void main(String[] args) {
    try {
      int a = 5 / 0;
    } catch (ArithmeticException e) {
      System.out.println("Arithmetic Exception caught");
    }
    System.out.println("Code continues...");
  }
}

Show Hint

Division by zero is caught, its message prints, then the line after the try catch also prints.
Updated On: Jul 2, 2026
  • Code continues...
  • Arithmetic Exception caught
  • Compilation error
  • Both (A) and (B)
Show Solution
collegedunia
Verified By Collegedunia

The Correct Option is D

Solution and Explanation

Step 1: The line \( a = 5 / 0 \) is integer division by zero, which throws an ArithmeticException at runtime.

Step 2: The catch block matches ArithmeticException, so it runs and prints "Arithmetic Exception caught".

Step 3: After the try catch finishes, control moves to the next line, which prints "Code continues...".

Step 4: Both lines print, so the output is option (A) plus option (B). Answer is (D).
Was this answer helpful?
0
0