Reputation: 4563
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.
Upvotes: 1
Views: 272
Reputation: 7044
Because consoleprogram extends the class program which contains a main method.
Upvotes: 0
Reputation: 4816
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.
Upvotes: 1