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?
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.
精彩评论