0 votes
in JAVA by
What is the output of the following Java program?

public class ExceptionHandlingExample {  

public static void main(String args[])  

{  

    try  

    {  

        int a = 1/0;  

        System.out.println("a = "+a);  

    }  

    catch(Exception e){System.out.println(e);}  

    catch(ArithmeticException ex){System.out.println(ex);}    

}  

}

1 Answer

0 votes
by

Output of the following program is as per below: 

Output

ExceptionHandlingExample.java:10: error: exception ArithmeticException has already been caught

catch(ArithmeticException ex){System.out.println(ex);}

^

1 error

Explanation

ArithmaticException is the subclass of Exception. Therefore, it can not be used after Exception. Since Exception is the base class for all the exceptions, therefore, it must be used at last to handle the exception. No class can be used after this.

Related questions

0 votes
asked Apr 9, 2021 in JAVA by Robindeniel
+3 votes
asked May 13, 2021 in JAVA by rajeshsharma
...