Skip to content
Related Articles

Related Articles

Java | Exception Handling | Question 8
  • Difficulty Level : Basic
  • Last Updated : 30 Sep, 2018




class Test
{
    public static void main (String[] args)
    {
        try
        {
            int a = 0;
            System.out.println ("a = " + a);
            int b = 20 / a;
            System.out.println ("b = " + b);
        }
  
        catch(ArithmeticException e)
        {
            System.out.println ("Divide by zero error");
        }
  
        finally
        {
            System.out.println ("inside the finally block");
        }
    }
}

(A) Compile error
(B) Divide by zero error
(C)

a = 0
Divide by zero error
inside the finally block

(D) a = 0
(E) inside the finally block


Answer: (C)

Explanation: On division of 20 by 0, divide by zero exception occurs and control goes inside the catch block.
Also, the finally block is always executed whether an exception occurs or not.


Quiz of this Question

My Personal Notes arrow_drop_up
Recommended Articles
Page :