Java OCA OCP Practice Question 863

Question

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

public class Main { 
   public static void main(String[] names) { 
      System.out.println(names[0]); 
   } 
} 
  • A. Main
  • B. The code does not compile.
  • C. The code throws an ArrayIndexOutOfBoundsException.
  • D. The code throws a NullPointerException.


C.

Note

Main is the name of the class, not an argument.

There are no other arguments, so names is an empty array.

Therefore, Option C is correct.




PreviousNext

Related