Java OCA OCP Practice Question 2614

Question

Consider the following program:

class Main {/*w  ww  .  java2 s  .  c  o m*/
        public static void main(String []args) {
                try {
                        assert false;
                }
                catch (RuntimeException re) {
                        System.out.println("In the handler of RuntimeException");
                }
                catch (Exception e) {
                        System.out.println("In the handler of Exception");
                }
                catch (Error ae) {
                        System.out.println("In the handler of Error");
                }
                catch (Throwable t) {
                        System.out.println("In the handler of Throwable");
                }
        }
}

This program is invoked in the command line as follows:

java Main

Which one of the following options correctly describes the behavior of this program?

  • a) This program prints the following: In the handler of RuntimeException.
  • b) This program prints the following: In the handler of Exception.
  • c) This program prints the following: In the handler of Error.
  • d) This program prints the following: In the handler of Throwable.
  • e) This program crashes with an uncaught exception AssertionError.
  • f) This program does not generate any output and terminates normally.


f)

Note

Since asserts are disabled by default, the program does not raise an AssertionError, so the program does not generate any output and terminates normally.

If the program were invoked by passing -ea in the command line, it would have printed "In the handler of Error" (since the program would have thrown an AssertionError).




PreviousNext

Related