Can we overload the main method in Java?

后端 未结 14 1873
不知归路
不知归路 2020-11-30 18:07

Can we overload a main() method in Java?

14条回答
  •  悲&欢浪女
    2020-11-30 18:33

    Yes you can Overload main method but in any class there should be only one method with signature public static void main(string args[]) where your application starts Execution, as we know in any language Execution starts from Main method.

    package rh1;
    
    public class someClass 
    {
    
        public static void main(String... args)
        {
            System.out.println("Hello world");
    
            main("d");
            main(10);
        }
        public static void main(int s)
        {
    
            System.out.println("Beautiful world");
        }
        public static void main(String s)
        {
            System.out.println("Bye world");
        }
    }
    

提交回复
热议问题