QuestionQ82

Java Basics

Given this code snippet from a compiled Java source file:

Question Image

and this output:

Question Image

Which command should be run to produce this output?

  • A java MyFile 2
  • B java MyFile 1 2 3 4
  • C java MyFile 1 2 2
  • D java MyFile 2 2
Explanation

args[2] accesses the third command-line argument. Supplying 1 2 2 makes that value 2, so the program prints Arg is 2.

Community Discussion

No comments yet. Be the first to start the discussion!