Bird
0
0

Identify the error in this Java program snippet:

medium📝 Debug Q7 of 15
Java - Command Line Arguments
Identify the error in this Java program snippet:
public class Demo {
  public static void main(String arg) {
    System.out.println(arg);
  }
}
Amain method parameter should be String[] not String
BMissing return type for main method
CSystem.out.println cannot print String
DClass name should be Main
Step-by-Step Solution
Solution:
  1. Step 1: Check main method parameter

    The main method must accept an array of Strings (String[]) to receive command-line arguments.
  2. Step 2: Analyze given code

    The parameter is declared as a single String (String arg), which is incorrect.
  3. Final Answer:

    main method parameter should be String[] not String -> Option A
  4. Quick Check:

    Main method must have String array parameter [OK]
Quick Trick: Main method parameter must be String[] args [OK]
Common Mistakes:
  • Using String instead of String[] for main parameter
  • Forgetting static keyword
  • Incorrect method signature

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes