Java OCA OCP Practice Question 913

Question

What is the output of the following when run as java MyClass myValue?

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


B.

Note

Array indexes begin with zero.

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

Therefore, the first argument is myValue, and Option B is correct.




PreviousNext

Related