What is the output of the following program?
1: public class Main { 2: public void start() { 3: try { 4: System.out.print("AAA"); 5: throw new Exception(); 6: } catch (Exception e) { 7: System.out.print("BBB"); 8: System.exit(0); 9: } finally { 10: System.out.print("CCC"); 11: } 12: } 13: public static void main(String[] args) { 14: new Main().start(); 15: } 16:}
B.
Line 4 prints AAA and line 5 throws an Exception.
Line 6 catches the exception, line 7 prints BBB and line 8 calls System.exit, which terminates the JVM.
The finally block does not execute.
public class Main { public void start() { try {/*from w ww .j a v a 2s . co m*/ System.out.print("AAA"); throw new Exception(); } catch (Exception e) { System.out.print("BBB"); System.exit(0); } finally { System.out.print("CCC"); } } public static void main(String[] args) { new Main().start(); } }