Bird
0
0

Which of the following is the correct declaration of the main method to receive command-line arguments in Java?

easy📝 Syntax Q3 of 15
Java - Command Line Arguments
Which of the following is the correct declaration of the main method to receive command-line arguments in Java?
Apublic static void main(String[] args)
Bpublic void main(String args[])
Cstatic public void main(String args)
Dpublic static int main(String[] args)
Step-by-Step Solution
Solution:
  1. Step 1: Understand main method signature

    The Java entry point must be public static void main with a single parameter of type String[].
  2. Step 2: Check each option

    public static void main(String[] args) matches the correct signature exactly.
    public void main(String args[]) is missing static and has wrong parameter type.
    static public void main(String args) has wrong parameter type and order.
    public static int main(String[] args) returns int which is invalid.
  3. Final Answer:

    public static void main(String[] args) -> Option A
  4. Quick Check:

    Correct main method signature requires public static void main(String[] args) [OK]
Quick Trick: Main method must be public static void with String array [OK]
Common Mistakes:
  • Using non-static main method
  • Wrong parameter type like String instead of String[]
  • Returning int instead of void

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes