java non-static method getBalance cannot be referenced from a static context

后端 未结 4 1849
北荒
北荒 2020-12-11 13:25

I\'m trying to refer to a method in another class and use that in a return statement in my other class. At the moment, all I get is the following error: non-static method ge

4条回答
  •  攒了一身酷
    2020-12-11 13:52

    You're trying to call a non-static method as if it were static. Assuming that you have a class Account, Account.getBalance() would only work for a static getBalance() method. You need an instance of Account in order to call a non-static getBalance() method.

提交回复
热议问题