Java OCA OCP Practice Question 2241

Question

Consider the following program:

public class Main {
     public static void main(String []args) {
         try {/*from ww w  .  j a  v a2  s.  c  o  m*/
             assert false;
         } catch(RuntimeException re) {
             System.out.println("RuntimeException");
         } catch(Exception e) {
             System.out.println("Exception");
         } catch(Error e) {        // LINE A
             System.out.println("Error" + e);
         } catch(Throwable t) {
             System.out.println("Throwable");
     }
   }
}

This program is invoked from the command line as follows:

java Main

Choose one of the following options describes the behavior of this program:

  • A. Compiler error at line marked with comment Line a
  • B. prints "runtimeexception" in console
  • C. prints "exception"
  • d. prints "error"
  • e. prints "throwable"
  • F. does not print any output on console


F.

Note

By default, assertions are disabled.

if -ea or the -enableassertions option to enable assertions, then the program would have printed "Error" since the exception thrown in the case of assertion failure is java.lang.AssertionError, which is derived from the Error class.




PreviousNext

Related