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

前端 未结 3 1863
暖寄归人
暖寄归人 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:35

    Membership is a class. Calling methods though it is only allowed if the method is static. Your getMonth method isn't static, so you will need an instance of the Membership class to call it. You already have a list of instances in your Club class, so pick one of those and call getMonth on it.

提交回复
热议问题