Open In App

Java | Exception Handling | Question 8

Like Article
Like
Save
Share
Report




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


Last Updated : 30 Sep, 2018
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads