Java主方法的方法签名是:

public static void main(String[] args) {
    ...
}

为什么这个方法必须是静态的?


当前回答

Static表示该方法是类方法。并且调用时不需要任何类的对象。

其他回答

static -当JVM调用主方法时,被调用的类不存在对象,因此它必须有静态方法来允许从类调用。

让我用更简单的方式来解释这些事情:

public static void main(String args[])

除了applet,所有Java应用程序都从main()开始执行。

关键字public是一个访问修饰符,允许从类外部调用成员。

使用Static是因为它允许调用main()而不必实例化该类的特定实例。

Void表示main()不返回任何值。

静态方法不需要任何对象。它直接运行,所以main直接运行。

The main method of the program has the reserved word static which means it is allowed to be used in the static context. A context relates to the use of computer memory during the running of the program. When the virtual machine loads a program, it creates the static context for it, allocating computer memory to store the program and its data, etc.. A dynamic context is certain kind of allocation of memory which is made later, during the running of the program. The program would not be able to start if the main method was not allowed to run in the static context.

由于程序从main()和开始执行,java是纯面向对象的程序,其中对象在main()中声明,这意味着main()在对象创建之前被调用,因此如果main()是非静态的,那么就需要一个对象,因为静态意味着不需要对象..........