
是的,在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 main method as: public static void main(String[] args) or a JavaFX application class must extend javafx.application.Application











