Java ACM JTF 包

标签 java

我对下面的代码有疑问。我想知道为什么即使 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/

相关文章:

java - 在 JTextField 中输入阿拉伯数字

Java套接字客户端到不同网络上的服务器。

java - 调用外部类和方法

java - 如何在android中使底部导航栏不透明?

java - 带有 jdbc 的 Spring Security 3.0

JavaFX FXMLLoader 无效属性

java - weld-osgi、pax-cdi 和fighterfish 之间有什么区别

java - 如何检索最大 id 值并存储在 int 变量中?

java - 使用 ViewPager 在 Xamarin.Android 上以轮播样式显示图像幻灯片并使用突出的子项进行填充,Viewpager 错误地计算参数

java - 使用正则表达式显示字母以外的字符