Consider the following program:
public class Main { public static void main(String []args) { try {/*www . java 2s.co m*/ int i = 10/0; // LINE A System.out.print("after throw -> "); } catch(ArithmeticException ae) { System.out.print("in catch -> "); return; } finally { System.out.print("in finally -> "); } System.out.print("after everything"); } }
Which one of the following options best describes the behavior of this program?
d.
the statement println("after throw -> "); will never be executed since the line marked with the comment Line a throws an exception.
the catch handles ArithmeticException, so println("in catch -> "); will be executed.
Following that, there is a return statement, so the function returns.
But before the function returns, the finally statement should be called, hence the statement println("in finally -> "); will get executed.
so, the statement println("after everything"); will never get executed.