Java OCA OCP Practice Question 936

Question

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

public class MyClass { 
        public static void main(String target[]) { 
           System.out.println(target.length()); 
        } 
} 
  • A. 0
  • B. 1
  • C. 2
  • D. The code does not compile.


D.

Note

Arrays expose a length variable.

They do not have a length() method.

Therefore, the code does not compile, and Option D is correct.




PreviousNext

Related