Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Java | Exception Handling | Question 8

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article




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
Last Updated : 30 Sep, 2018
Like Article
Save Article
Similar Reads