简体   繁体   English

Java ACM JTF软件包

[英]Java ACM JTF Package

I have a doubt in the below piece of code. 我对下面的代码有疑问。 I wanted to know why does the code compile and run correctly even though main method is not present? 我想知道为什么即使没有main方法,代码也可以正确编译并运行?

import acm.program.*;  

public class HelloConsole extends ConsoleProgram {  

   public void run() {  
      println("hello, world");  
   }    
}

Thanks. 谢谢。

This is by design of the ACM program classes. 这是由ACM程序类设计而成的。 See the javadocs : 参见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. 与acm.program程序包相关联的常规使用模式使学生从公共静态void mainin的命令式风格转移到更具教学法意义的框架中,使学生始终在对象的上下文中进行工作。

In this case you override the init/run methods as opposed to writing a main method. 在这种情况下,您将覆盖init / run方法,而不是编写main方法。

因为consoleprogram扩展了包含主方法的类程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM