Can a main method in Java return something?

前端 未结 6 1919
情话喂你
情话喂你 2020-11-29 04:58

I went through an interview recently and they ask me two questions in core Java.

Q 1.

Can we write a java class with:

public s         


        
6条回答
  •  迷失自我
    2020-11-29 05:42

    Yes, we can write main method with a return type other than void. This simply means that we can overload our main method. Some examples are

    1. public static void main(String ... x){ }
    2. public static int main(String []args){ }
    3. public static void main(string array[]){ }

    But, note here that the compiler will only know

    public static void main(String []args){ }
    

    If above method is not present it will not compile.

提交回复
热议问题