【发布时间】:2019-08-17 15:07:07
【问题描述】:
我不明白我的编译器如何找不到类Weight,考虑到我不是已经在我的public boolean checkWeight 方法中实现了吗?编译器指向的行:
`Weight first = new Weight();`
和
`Weight second = new Weight();`
public class Guard {
int stashWeight;
public Guard ( int maxWeight ) {
this.stashWeight = maxWeight;
}
public boolean checkWeight (Weight maxWeight) {
if ( maxWeight.weight >= stashWeight ) {
return true;
} else {
return false;
}
}
public static void main (String[] args ) {
Weight first = new Weight();
first.weight = 3000;
Weight second = new Weight();
second.weight = 120;
Guard grams = new Guard(450);
System.out.println("Officer, can I come in?");
boolean canFirstManGo = grams.checkWeight(first);
System.out.println(canFirstManGo);
System.out.println();
System.out.println("Officer, how about me?");
boolean canSecondManGo = grams.checkWeight(second);
System.out.println(canSecondManGo);
}
}
【问题讨论】:
-
你导入正确的
Weight类了吗? -
你的体重等级在哪里
-
我可能已经昏迷了。出于某种未知的原因,我的新手头脑认为我已经做了我的体重等级:public boolean checkWeight (maxWeight Weight)。感谢大家的提醒
标签: java class inheritance methods