+ 1
Why main method is defined public static
public static void main(String[] arcs) {}
2 Antworten
+ 8
[ public ]
Because the program entry point needs to expose to the public so it can be invoked/called and run properly.
[ static ]
Because the program was invoked/called without its class instantiated during runtime. You may imagine the program was called like this
MyClass.main();
instead of this
MyClass obj = MyClass();
obj.main();
P/S: This question has been asked so many times so please use the search in Discussion next time.
+ 4
Based on Zephyr Koo's answer, If main method is not declared static, you need to create object so that your problem can run successfully😂