Java OCA OCP Practice Question 3034

Question

Given:

1. class Shape {  
2.   static void doShape(int x) {  
3.     assert (x < 0) : "hotel";  
4.   }  //from  w  w w . j  ava2 s .  c o m
5. }  
6. public class Main extends Shape {  
7.   public static void main(String[] args) {  
8.      doShape(-5);  
9.      int y = 0;  
10.     assert (y < 0) : "motel";  
11. } } 

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

  • A. java Main
  • B. java -ea Main
  • C. java -da:Shape Main
  • D. java -da:Main Main
  • E. java -ea -da:Shape Main
  • F. java -ea -da:Main Main


A, C, D, and F are correct.

Note

When assertions are enabled, the Main class will throw an AssertionError, the Shape class will not.

Invocations A, C, and D do not enable assertions for Main.

F is correct because although assertions were enabled, the "-da" switch selectively disabled assertions for the Main class.

B and E are incorrect because assertions are enabled for Main.




PreviousNext

Related