开发者

Java ACM JTF Package

开发者 https://www.devze.com 2023-02-28 10:31 出处:网络
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?

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?

import acm.program.*;  

public class HelloConsole extends ConsoleProgram {  

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

Thanks.


This is by design of the ACM program classes. See the 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.

In this case you override the init/run methods as opposed to writing a main method.


Because consoleprogram extends the class program which contains a main method.

0

精彩评论

暂无评论...
验证码 换一张
取 消