Multiple main() methods in java

后端 未结 10 651
忘了有多久
忘了有多久 2020-12-28 08:53

I was wondering what the effect of creating extra main methods would do to your code.

For example,

public class TestClass {
    public static void ma         


        
10条回答
  •  难免孤独
    2020-12-28 09:19

    You can have only one main method in one class, But you can call one main method to the another explicitly

    class Expmain
    {
        public static void main(String[] ar)
        {
            System.out.println("main 1");
        }
    }
    
    class Expmain1
    {
        public static void main(String[] ar)
        { 
            System.out.println("main 2");
            Expmain.main(ar);
        }
    }
    

提交回复
热议问题