Bird
0
0

What will be the output of the following Java program if run with command line arguments: java Test Hello World?

medium📝 Predict Output Q13 of 15
Java - Command Line Arguments
What will be the output of the following Java program if run with command line arguments: java Test Hello World?
public class Test {
    public static void main(String[] args) {
        System.out.println(args[0] + " " + args[1]);
    }
}
Aargs[0] args[1]
BHello World
CWorld Hello
DCompilation error
Step-by-Step Solution
Solution:
  1. Step 1: Understand command line arguments array

    args[0] is the first argument "Hello", args[1] is the second argument "World".
  2. Step 2: Check the print statement

    The program prints args[0] + " " + args[1], which outputs "Hello World".
  3. Final Answer:

    Hello World -> Option B
  4. Quick Check:

    args[0] + args[1] = Hello World [OK]
Quick Trick: args[0] is first argument, args[1] second [OK]
Common Mistakes:
  • Confusing args index order
  • Expecting variable names printed literally
  • Assuming compilation error without syntax issues

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes