Java MCQ: What is the correct syntax to declare a main method in Java?
Answer:
Explanation:
The main method in Java is the entry point of any Java application. The correct syntax for the main method is public static void main(String[] args)
. This method must be declared as public
so that it can be accessible to the JVM to execute the program.
The static
keyword allows the JVM to call the method without needing to instantiate the class. The void
return type indicates that the method does not return any value. Finally, String[] args
is the parameter that allows the program to accept command-line arguments.
Understanding the main method’s syntax and purpose is fundamental for developing Java applications, as it is the first method that gets executed in a Java program.
Reference links:
https://www.rameshfadatare.com/learn-java-programming/
https://www.javaguides.net/p/java-tutorial-learn-java-programming.html