Can the main( ) method be specified as private or protected?

前端 未结 5 594
余生分开走
余生分开走 2020-12-18 04:24

Can the main() method be specified as private or protected?

Will it compile?

Will it run?

5条回答
  •  忘掉有多难
    2020-12-18 04:51

    Yes, It will compile but Not Run. It will give you the following errors

    Error: Main method not found in class A, please define the main method as: public static void main(String[] args) or a JavaFX application class must extend javafx.application.Application

    Following are the simple code for testing

    class A {
      private static void main(String arg[])
      {
      System.out.print(2+3);
      }
    }
    

提交回复
热议问题