Correct Answer: B
Explanation/Reference:
Explanation:
The command line javac Counter.java
Will compile the code.
The command line java ea Counter
Will run the cod with assertions enabled.
Assertion is true because getCount(arr) = 3 and Length of array is 4
The following line:
assert (getCount(arr) < arr.length);
where the Boolean expression getCount(arr) < arr.length will evaluate to false, will ensure that an
AssertionError is thrown at runtime.
Note:The javac command compiles Java source code into Java bytecodes. You then use the Java
interpreter - the java command - to interprete the Java bytecodes.
Note 2:The java tool launches a Java application. It does this by starting a Java runtime environment,
loading a specified class, and invoking that class's main method. The method declaration must look like
the following: public static void main(String args[])
Paramater ea:
-enableassertions[:<package name>"..." | :<class name> ] -ea[:<package name>"..." | :<class name> ]
Enable assertions. Assertions are disabled by default. With no arguments, enableassertions or -ea enables
assertions.
Note 3:
An assertion is a statement in the JavaTM programming language that enables you to test your
assumptions about your program.
Each assertion contains a boolean expression that you believe will be true when the assertion executes. If
it is not true, the system will throw an error.