Can there exist two main methods in a Java program?

后端 未结 16 627
后悔当初
后悔当初 2020-12-08 02:21

Can there exist two main methods in a Java program?

Only by the difference in their arguments like:

public static void main(String[] args)

16条回答
  •  有刺的猬
    2020-12-08 03:16

    As long as method parameters (number (or) type) are different, yes they can. It is called overloading.

    Overloaded methods are differentiated by the number and the type of the arguments passed into the method

    public static void main(String[] args)
    

    only main method with single String[] (or) String... as param will be considered as entry point for the program.

提交回复
热议问题