Java OCA OCP Practice Question 899

Question

What is the result of running the following as java MyClass?

public class MyClass { 
       public static void main(String... original) { 
           String... copy = original; 
           System.out.println(copy.length + " " + copy[0]); 
        } 
} 
  • A. 0
  • B. 0 followed by an exception
  • C. 1 followed by an exception
  • D. The code does not compile.


D.

Note

Three dots in a row is a varargs parameter.

While varargs is used like an array from within the method, it can only be used as a method parameter.

This syntax is not allowed for a variable, making Option D the answer.




PreviousNext

Related