Exceptions

Q1: What will be the output of the program?
try 
{ 
    int x = 0; 
    int y = 5 / x; 
} 
catch (Exception e) 
{
    System.out.println('Exception'); 
} 
catch (ArithmeticException ae) 
{
    System.out.println(' Arithmetic Exception'); 
} 
System.out.println('finished');

A Exception

B Compilation fails.

C Arithmetic Exception

D finished

ANS:A - finished

Compilation fails because ArithmeticException has already been caught. ArithmeticException is a subclass of java.lang.Exception, by time the ArithmeticException has been specified it has already been caught by the Exception class.



img not found
img

For help Students Orientation
Mcqs Questions

One stop destination for examination, preparation, recruitment, and more. Specially designed online test to solve all your preparation worries. Go wherever you want to and practice whenever you want, using the online test platform.