What output is produced for the command: "java cmd a b c d", when following…

2024

What output is produced for the command: "java cmd a b c d", when following code is run? class cmd { public static void main(String args[]) { System.out.println(args[2]); } }

  1. A.

    c

  2. B.

    cmd

  3. C.

    b

  4. D.

    a

  5. E.

    Question not attempted

Attempted by 104 students.

Show answer & explanation

Correct answer: A

When running "java cmd a b c d", arguments are stored in the String array args. Index 0 is 'a', index 1 is 'b', and index 2 is 'c'. The code prints args[2], resulting in output: c.

Explore the full course: Up Lt Grade Assistant Teacher 2025