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.
因为consoleprogram扩展了包含主方法的类程序。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.