The interface I, base class B, and derived class D have a defined data field of same type and name x. A method getX() is implemented to return x in B and D:
interface I {
int getX();
int x = 10;
}
class B implements I {
public int getX() { return x; }
int x = I.x*2;
}
class D extends B {
public int getX() { return x; }
int x = super.x*2;
}
Note how x is/are initialized in I, B and D. We create an instance of D and assign it to a reference of type I:
I i = new D();
What would be the return value of calling i.getX()
?