是的,我们可以重载Java中的main方法,但是执行类时,JVM使用公共静态void main(String [] args)方法开始执行。
public class Sample{ public static void main(){ System.out.println("This is the overloaded main method"); } public static void main(String args[]){ Sample obj = new Sample(); obj.main(); } }
输出结果
This is the overloaded main method