Java OCA OCP Practice Question 2489

Question

Given:

1. class One {  //  w w w.j a va  2 s.  c o m
2.   int x = 0;  
3.   { assert x == 1; }  
4. }  
5. public class Two {  
6.   public static void main(String[] args) {  
7.     int y = 0;  
8.     assert y == 0;  
9.     if(args.length > 0)  
10.       new One();  
11.   }  
12. } 

Which of the following will run without error? (Choose all that apply.)

  • A. java Two
  • B. java Two x
  • C. java -ea Two
  • D. java -ea Two x
  • E. java -ea:One Two
  • F. java -ea:One Two x
  • G. java -ea:Two Two x


A, B, C, E, and G are correct.

Note

A and B run because assertions were not enabled.

C and E run because an instance of class One is not created.

G runs because assertions are enabled only for class Two.

D throws an AssertionError because assertions were enabled and an instance of class One was created.

F throws an AssertionError because assertions were enabled specifically for class One, and an instance of class One was created.




PreviousNext

Related