What is the result when infected() is invoked?
A.
before try catch finally after
B.
before catch finally after
C.
before catch after
D.
before catch finally
E.
before catch
Explanation:
The following line throws and exception:
int i = 1/0;
This exception is caught by:
catch(Exception e) {
System.out.print(“catch “);
throw e;
Lastly, the finally statement is run as the finally block always executes when the try block exits.
This ensuresthat the finally block is executed even if an unexpected exception occurs.
Reference: Java Tutorial,The finally Block
D
D
D
before catch finally Exception in thread “main” java.lang.ArithmeticException: / by zero
at Test.infected(Test.java:14)
at Test.main(Test.java:6)