Open In App
Related Articles

Java | Exception Handling | Question 8

Improve Article
Save Article
Like Article

class Test
    public static void main (String[] args)
            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");
            System.out.println ("inside the finally block");

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

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

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 30 Sep, 2018
Like Article
Save Article
Similar Reads