标签: static

  • Java main函数为何为static

    前几天,曾同学问我为什么 Java main 函数带有 static,我一时也不明白,只好说是 Java 的 main 函数的格式是规定的,我也一直这样写下来,然后赶紧去查。

    原谅我,我忘记这是在哪个网站/论坛找到的了,因为当时没记录,只有在聊天记录中找到了当时copy下来的我觉得可以说得过去的解释。

    The method is static because otherwise there would be ambiguity: which constructor should be called? Especially if your class looks like this:

    public class JavaClass{
        protected JavaClass(int x){}
        public void main(String[] args){
        }
    }
    

    (更多…)