Why can other methods be “static” but a constructor cannot?

后端 未结 15 1232
借酒劲吻你
借酒劲吻你 2020-12-04 17:59

I do not understand why the main method has to be static. I understand static variables but static methods are difficult for me to grasp. Do static method exists so that one

15条回答
  •  日久生厌
    2020-12-04 18:25

    Static Belongs to Class, Constructor to Object

    We know that static methods, block or variables belong to the class. Whereas a Constructor belongs to the object and called when we use the new operator to create an instance. Since a constructor is not class property, it makes sense that it’s not allowed to be static.

提交回复
热议问题