Java OCA OCP Practice Question 148

Question

Given the following class definition, which command will output the message test-test?

package mypkg; 
public class MyClass { 
   public static void main(String... theInput) { 
      System.out.print(theInput[2]); 
   } 
} 
  • A. java mypkg.MyClass deer 5 "test-test deer"
  • B. java mypkg.MyClass "test-test deer" deer 3
  • C. java mypkg.MyClass Red deer test-test deer
  • D. java mypkg.MyClass My "deer test-test"


C.

Note

The application prints the third argument of the input methods.

Note that double quotes "" can be used to group input arguments.

The third argument of Option A is test-test deer.

The third argument of Option B is 3.

The third argument of Option C is test-test, making it the correct answer.

Option D only has two input arguments, leading to an ArrayIndexOutOfBoundsException trying to read the third argument at runtime.




PreviousNext

Related