在Java中,我们可以将主方法声明为私有的吗?
是的,在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登录后复制