JAVA Syllabus
QUESTIONS & ANSWERS

What happens if String args[] is not written in main()?

In Java, the String args[] parameter in the main() method is used to pass command line arguments to the Java program. If this parameter is not specified in the main() method signature, the Java compiler will not recognize the method as the starting point of the program, and the program will not execute correctly.

If you omit the String args[] parameter in the main() method, you will receive a compile-time error indicating that the main() method is not properly declared. The error message may vary depending on the Java compiler being used, but it will generally be something like "Error: Main method not found in class YourClassName, please define the main method as: public static void main(String[] args)".

Therefore, it is essential to include the String args[] parameter in the main() method signature if you want to pass command line arguments to your Java program.

03/03/2023, 6:25 am Read : 189 times