Java
Programming and Technical
Programming
Technical
Observe the code.
public class Sample {
public static void main(String args[]) {
int i=10,j=0,k;
try {
k=i/j;
}
catch(Exception e) {
System.out.println("Exception");
}
catch(ArithmeticException e) {
System.out.println("Arithmetic exception");
}
}
}
Predict the output.
A. ArithmeticException
B. Compilation Fails
C. Exception
ArithmeticException
D. Runtime exception
Read Solution (Total 2)
-
- C. Exception
Arithmetic Exception - 2 years agoHelpfull: Yes(0) No(0)
- (C) Exception
Here the catch block for "Exception" will catch the exception first, and the catch block for "ArithmeticException" will become unreachable. Therefore, the output of the program will be "Exception". - 1 year agoHelpfull: Yes(0) No(0)
Java Other Question