Bird
0
0

What will be the output of this program when run with no command line arguments? public class Demo { public static void main(String[] args) { System.out.println(args.length); } }

medium📝 Predict Output Q5 of 15
Java - Command Line Arguments
What will be the output of this program when run with no command line arguments? public class Demo { public static void main(String[] args) { System.out.println(args.length); } }
Anull
B0
C1
DArrayIndexOutOfBoundsException
Step-by-Step Solution
Solution:
  1. Step 1: Understand args array when no arguments passed

    If no arguments are passed, args is an empty array with length 0.
  2. Step 2: Print args.length

    The program prints 0 because args.length is 0.
  3. Final Answer:

    0 -> Option B
  4. Quick Check:

    No arguments means args.length = 0 [OK]
Quick Trick: No args means args.length is zero, not null [OK]
Common Mistakes:
  • Expecting null instead of empty array
  • Thinking args.length is 1
  • Expecting exception when no args

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes