The answer is yes, the parameter of the main() method must be an array of strings, not other types .
Change the parameter type to String below, and then run the verification.
package com.magic.main;
public class MainDemo {
public static void main(String args) {
System.out.println("Hello World");
}
}
Running directly in the IDE will output the following error message
错误: 在类 com.magic.main.MainDemo 中找不到 main 方法, 请将 main 方法定义为:
public static void main(String[] args)
否则 JavaFX 应用程序类必须扩展javafx.application.Application
When introducing varargs, you can pass varargs of string type as parameters to the main() method, but the varargs must be an array.
package com.magic.main;
public class MainDemo {
public static void main(String[] args) {
System.out.println("Hello World");
}
}
Or use the variable-length parameter form:
package com.magic.main;
public class MainDemo {
public static void main(String... args) {
System.out.println("Hello World");
}
}
String[] args is equivalent to String... args , these two forms cannot exist at the same time, such as the following definition is wrong:
package com.magic.main;
public class MainDemo {
public static void main(String[] args) {
System.out.println("Hello World");
}
public static void main(String... args) {
System.out.println("Hello World");
}
}
For more knowledge points related to Java interviews, you can pay attention to the [Java Interview Manual] applet, which involves Java foundation, multithreading, JVM, Spring, Spring Boot, Spring Cloud, Mybatis, Redis, database, data structure and algorithm.
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。