Can there exist two main methods in a Java program?

后端 未结 16 784
后悔当初
后悔当初 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:10

    The signature of main method must be

    public static void main(String[] args) 
    
    • The parameter's name can be any valid name
    • The positions of static and public keywords can be interchanged
    • The String array can use also the varargs syntax

    A class can define multiple methods with the name main. The signature of these methods does not match the signature of the main method. These other methods with different signatures are not considered the "main" method.

提交回复
热议问题