更新时间:2022-04-06 08:32:17
您正在引用当前实例的值和不是晚餐课。与任何覆盖一样,您需要引用超类。例如:
You are referencing the current instance''s value and not the supper classes. As in any overriding, you need to reference the super class. For example:
class Foo {
int val = 1;
int getVal() {
return this.val;
}
}
class Bar extends Foo {
int val = 2;
int getFooVal() {
return super.val;
}
}
// later on:
Bar b = new Bar();
b.getVal(); // returns 2
b.getFooVal(); // returns 1