为什么JAVA编程里把主函数放在定义的类中 

2024-12-05 06:39:21
推荐回答(1个)
回答1:

The Java Virtual Machine (JVM) has to start the application somewhere. As Java does not have a concept of “things outside of a class” the method that is called by the JVM has to be in a class. And because it is static, no instance of that class is created yet.
根据官方文档,这个语法现象建立于java虚拟机设计。在建立虚拟机的时候就没有这个概念。虚拟机在执行程序时候首先在main方法,没有就报错。你可以试试建立一个类,然后注释main方法,会报错:在类中找不到main方法。