Question 742: 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");
tcs
wipro
infosys
general
aptitude
exceptions
Compilation fails becauseArithmeticExceptionhas already been caught.ArithmeticExceptionis a subclass ofjava.lang.Exception, by time theArithmeticExceptionhas been specified it has already been caught by theExceptionclass.IfArithmeticExceptionappears beforeException, then the file will compile. When catching exceptions the more specific exceptions must be listed before the more general (the subclasses must be caught before the superclasses).