Java OCA OCP Practice Question 867

Question

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

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


B.

Note

The name of the program is Main, and there is only one argument because double quotes are used around the value.

That argument is a String with three characters: 1, a space, and 2.

Therefore, the program outputs 1, and Option B is correct.




PreviousNext

Related