nerdexam
Oracle

1Z0-804 · Question #45

Given: And the commands: javac Test.java java ea Test What is the result?

The correct answer is D. Standard Edition is printed and an Assertion Error is thrown. will compile the program. As for command line: First the code will produce the output: Standard Edition The ea option will enable assertions. This will make the following line in the switch statement to default: assert false; This will throw an assertion error. This error will…

Exceptions and Assertions

Question

Given:

And the commands:

javac Test.java java ea Test What is the result?

Exhibit

1Z0-804 question #45 exhibit

Options

  • ACompilation fails
  • BStandard Edition
  • CStandard Edition
  • DStandard Edition is printed and an Assertion Error is thrown

How the community answered

(49 responses)
  • A
    10% (5)
  • B
    6% (3)
  • C
    4% (2)
  • D
    80% (39)

Explanation

will compile the program. As for command line: First the code will produce the output: Standard Edition The ea option will enable assertions. This will make the following line in the switch statement to default: assert false; This will throw an assertion error. This error will be caught. An the class of the assertion error (classjava.lang.AssertionError) will be printed by the following line: System.out.println(e.getClass()); Note:The java tool launches a Java application. It does this by starting a Java runtime environment, loading aspecified class, and invoking that class's main method. The method declaration must look like the following: public static void main(String args[]) -enableassertions[:<package name>"..." | :<class name> ] -ea[:<package name>"..." | :<class Enable assertions. Assertions are disabled by default. With no arguments, enableassertions or - ea enablesassertions. An assertion is a statement in the JavaTM programming language that enables you to test your assumptionsabout your program. Each assertion contains a boolean expression that you believe will be true when the assertion executes. If it isnot true, the system will throw an error. public class AssertionError extends Error Thrown to indicate that an assertion has failed. The javac command compiles Java source code into Java bytecodes. You then use the Java interpreter - the java command - to interprete the Java bytecodes.

Topics

#assert statement#AssertionError#-ea flag#assertion enabling

Community Discussion

No community discussion yet for this question.

Full 1Z0-804 Practice