Non-static method (method name()) cannot be referenced from a static context. Why?

前端 未结 3 1862
暖寄归人
暖寄归人 2021-01-15 20:30

I\'m really confused with this! I have 2 classes, Club and Membership. In Membership I have the method, getMonth(), and in

3条回答
  •  情话喂你
    2021-01-15 20:42

    Static modifier make method/field to be part of class not object (instance). You call it by using class name as reference (or object reference, but that is bad practice). If method/field is not static it must to be called via reference to class object (instance).

提交回复
热议问题