Java OCA OCP Practice Question 942

Question

What is the result of the following when called as java counting.MyClass?

package counting; 
import java.util.*; 
public class MyClass { 
     ? 
        public static void main(String... args) { 
           Arrays.sort(args); 
           System.out.println(Arrays.toString(args)); 
        } 
} 
  • A. null
  • B. []
  • C. The code does not compile.
  • D. The code compiles but throws an exception at runtime.


B.

Note

Since no arguments are passed from the command line, this creates an empty array.

Sorting an empty array is valid and results in an empty array.

Therefore, Option B is correct.




PreviousNext

Related