是的,在java中我们可以将main方法声明为私有的。
它可以成功编译,没有任何错误,但在运行时会提示main方法不是公共的。
示例:class privatemainmethod { private static void main(string args[]){ system.out.println("welcome to tutorials point"); }}
上述代码在编译时成功运行,但在运行时会抛出错误。
输出:error: main method not found in class privatemainmethod, please define the mainmethod as:public static void main(string[] args)or a javafx application class must extend javafx.application.application
以上就是在java中,我们可以将主方法声明为私有的吗?的详细内容。