Java OCA OCP Practice Question 877

Question

What is the output of the following when run as java unix.Main A B?

package unix; 
import java.util.*; 
public class Main { 
   public static void main(String[] args) { 
      Arrays.sort(args); 
      String result = Arrays.binarySearch(args, args[0]); 
      System.out.println(result); 
   } 
} 
  • A. 0
  • B. 1
  • C. The code does not compile.
  • D. The code compiles but throws an exception at runtime.


C.

Note

Binary search returns an int representing the index of a match or where a match would be.

An int cannot be stored in a String variable.

The code does not compile and the answer is Option C.




PreviousNext

Related