我对下面的代码有疑问。我想知道为什么即使 main 方法不存在,代码也能正确编译和运行?
import acm.program.*;
public class HelloConsole extends ConsoleProgram {
public void run() {
println("hello, world");
}
}
谢谢。
最佳答案
这是 ACM 程序类的设计。请参阅javadocs :
The conventional pattern of use associated with the acm.program package moves students away from the imperative style of public static void maininto a more pedagogically defensible framework in which students are always working in the context of an object.
在这种情况下,您将重写 init/run 方法,而不是编写 main 方法。
关于Java ACM JTF 包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5782961/