What if main method is inside “non public class” of java file?

后端 未结 7 2169
半阙折子戏
半阙折子戏 2020-11-30 12:40

I have a java file containing more than one class, out of which one is public. If main method is inside a non-public class. I can\'t run that java file. Why is that? and the

7条回答
  •  执笔经年
    2020-11-30 13:18

    Simple Answer. You can't. You need to have main method in a public class and its signature should be public static void main(String... args)

    there is no compilation error

    Why there would be? You are doing nothing wrong as far as compilation rules are concerned. Only thing is that your non-public-class-main-method won't work as an entry point of your code.

提交回复
热议问题