Java OCA OCP Practice Question 2813

Question

Given:

2. public class Main {  
3.   static int count = 0;  
4.   public static void main(String[] args) {  
5.     assert(doShape(5));  
6.   }  
7.   static boolean doShape(int x) {   
8.     count += x;  
9.     return true;  
10. } } 

Which are true? (Choose all that apply.)

  • A. The code compiles using javac -ea Main.java
  • B. The assert statement on line 5 is used appropriately.
  • C. The code compiles using javac -source 1.3 Main.java
  • D. The code compiles using javac -source 1.4 Main.java
  • E. The code compiles using javac -source 1.6 Main.java
  • F. The code will not compile using any version of the javac compiler.


D and E are correct

Note

D and E are correct (and C is incorrect) because "assert" was not a keyword until Java 1.4.

A is incorrect because -ea is a java command, not javac.

B is incorrect because an assertion should never cause a state change.

F is incorrect based on the above.




PreviousNext

Related