我对编程还很陌生,但在 C 语言中,我会有一个 main 函数来调用运行程序所需的所有其他方法。不过,在 Java 中,我正在查看 this - 这建议将 main() 方法放在它自己的类中,该类的职责仅是初始化程序。我是否应该有另一个仅调用方法(即运行程序?)的类(例如,“系统”类)。如果是这样,主类的命名是否有任何约定?
最佳答案
The main method is similar to the main function in C and C++; it's the entry point for your application and will subsequently invoke all the other methods required by your program.
方法签名
public static void main(String[] args)
任何类都可以包含 main
方法,但只有一个
调用类main
方法
java MyApp arg1 arg2
其中 MyApp 是一个包含 main
方法的类。
关于java - Java 的 main() 方法及其包含类应该做什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15866141/