public static void main(String arg[ ] ) in java is it fixed?

前端 未结 9 1373
离开以前
离开以前 2020-12-03 03:25

I was recently asked in an exam if public static void main(String arg[]) format of main method was fixed? Can we change it? Can we use main

9条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-03 04:08

    I cannot answer for the arguments of the method but it must be public because the jvm must be able to access the function and it must be static because the jvm does not know how to create an instance of your class.

    This post provides a good detailed answer about the reasoning for static: Why is the Java main method static?

    This post provides a good answer for why main is void: Why is main() in java void?

提交回复
热议问题