Java OCA OCP Practice Question 1404

Question

What is the output of the following when run as java Main seed flower plant?

package unix; // ww w.ja va2  s. com

import java.util.*; 

public class Main { 

   public static void main(String[] args) { 
      int result = Arrays.binarySearch(args, args[0]); 
      System.out.println(result); 
  } 
} 
  • A. 0
  • B. 1
  • C. 2
  • D. The code does not compile.
  • E. The code compiles but throws an exception at runtime.
  • F. The output is not guaranteed.


F.

Note

The array is not sorted.

It does not meet the pre-condition for a binary search.

Therefore, the output is not guaranteed and the answer is Option F.




PreviousNext

Related