Java OCA OCP Practice Question 2766

Question

Given:

3. class Shape { void print() { assert true; } }  
4. public class Main extends Shape {  
5.   public static void main(String[] args) {  
6.     new Main().go(args);  
7.   }  //www.  j  ava 2 s  .  co  m
8.   void go(String[] args) {  
9.     if(args.length > 0)  print();  
10.     if(args[0].equals("x")) System.out.print("x ");  
11.     if(args[0] == "x") System.out.println("x2 ");  
12. } } 

And (if the code compiles), the invocation:

java -ea Boombox2 x 

What is the result?

  • A. x
  • B. x x2
  • C. An error is thrown at runtime.
  • D. Compilation fails due to an error on line 3.
  • E. Compilation fails due to an error on line 8.
  • F. Compilation fails due to an error on line 9.


C is correct.

Note

A NoClassDefFoundError is thrown.

It's lame, but you have to watch out for this kind of thing.

The invocation should be java -ea Main x (both B's are capitalized).

If the invocation was correct, the answer would be A.




PreviousNext

Related