making an instance before calling non static method in java

后端 未结 4 1623
长发绾君心
长发绾君心 2021-01-20 16:53

Hi could someone please explain to me why you have to create an instance before calling a non static method to the main function in java? What is the reasoning behind this?<

4条回答
  •  感动是毒
    2021-01-20 17:04

    All the Static things of a class always belongs to a class and they are treated as a properties of the class .That's why they can be called by their name in that class, and called outside the class with the class name.

    All the Non-Static things of a class always belongs to an object, they are always treated as properties of an object. That's why they can only be called after creating an object by a (.) dot operator.

提交回复
热议问题