1Z0-804 · Question #138
Given: And the commands: javac Counter.java java ea Counter What is the result?
The correct answer is B. 3. The command line javac Counter.java Willcompile the code. The command line java ea Counter Willrun 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…
Question
Given:
And the commands:
javac Counter.java java ea Counter What is the result?
Exhibit
Options
- A2
- B3
- CNullPointException is thrown at runtime
- DAssertionError is thrown at runtime
- ECompilation fails
How the community answered
(22 responses)- B77% (17)
- C5% (1)
- D14% (3)
- E5% (1)
Explanation
The command line javac Counter.java Willcompile the code. The command line java ea Counter Willrun 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 anAssertionError is thrown at runtime. Note1: 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 aspecified 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 Enable assertions. Assertions are disabled by default. With no arguments, enableassertions or - ea enablesassertions. Note 3: 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.
Topics
Community Discussion
No community discussion yet for this question.
