For example, the output of the following program will be:
t.f=3 p.f=1
public class FieldSignatures {
static class P {
int f;
}
static class S extends P {
int f;
}
static class T extends S {
T() {
((P)this).f = 1;
((S)this).f = 2;
this.f = 3;
}
}
public static void main(String[] args) {
T t = new T();
P p = t;
System.out.println("t.f="+t.f+" p.f="+p.f);
}
}
1 comment:
Never notice this overridden field issue, because generally I will never override a field when using Java. Thanks for pointing out.
Post a Comment