java静态变量访问,如何在java中访问对象的静态变量?

I am working on a program where i have to include two static variables. I included them in my constructor before creating an array of ten objects. Later on, I tried to implement one of the static variables in the following way:

if (finalScore >= students.get(0).minA){

finalLetterGrade = "A";

aCounter++;

//(student.get(0).minA = 90)

The program shouldve worked fine, however Ecipse isn't allowing me to save the program because of the following error message:

"The static field ClassGrade.minA should be accessed in a

static way"

The error pops up at the first line of the code that i provided. Could anyone explain to me the correct way to supposedly access a static variable of an object in java, or at the very least advise me on how to get past this error message and save\run my program?

解决方案

You get the warning because static methods should be accessed via their container class itself (Classname.staticMethod()), not by one of its instances. Change

if (finalScore >= students.get(0).minA)

to

if (finalScore >= ClassGrade.minA)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值