Java OCA OCP Practice Question 1366

Question

What is the result of the following when called as java mypkg.Main?

package mypkg; /*  www.ja va2 s  . c o m*/
import java.util.*; 
public class Main { 
? 
   public static void main(String[] args) { 
      args = new String[] {"0", "1", "01", "10" }; 
? 
      Arrays.sort(args); 
      System.out.println(Arrays.toString(args)); 
   } 
} 
  • A. []
  • B. [0, 01, 1, 10]
  • C. [0, 01, 10, 1]
  • D. [0, 1, 01, 10]
  • E. The code does not compile.
  • F. The code compiles but throws an exception at runtime.


B.

Note

While no arguments are passed from the command line.

This doesn't matter because the main() method redefines the args array.

Remember that String values sort alphabetically rather than by number.

01 sorts before 1, and Option B is correct.




PreviousNext

Related