Why is the Java main method static?

前端 未结 30 2137
离开以前
离开以前 2020-11-22 01:41

The method signature of a Java main() method is:

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

Is the

30条回答
  •  甜味超标
    2020-11-22 02:16

    Let me explain these things in a much simpler way:

    public static void main(String args[])
    

    All Java applications, except applets, start their execution from main().

    The keyword public is an access modifier which allows the member to be called from outside the class.

    static is used because it allows main() to be called without having to instantiate a particular instance of that class.

    void indicates that main() does not return any value.

提交回复
热议问题