what is the way to access grand parent's field

hello all,

please go through the code below and suggest a way to access class X's 'i' without a method call (assume all i have is a reference for class X ex. X ref=null;)

class X

{

int i=10;

}

class A extends X

{

int i=10;

}

class B extends A

{

B()

{

//here i need to access class X's i and not class A's i..

//if i do super.i -i get class A's i;;;; but i want class X's i

}

}

[495 byte] By [varun_tayura] at [2007-11-27 8:22:50]
# 1

The field is determined by the (compile-time) type of the variable.

Therefore, in order to access X.i you need to have a variable of type X.

Obviously, a variable of type X can refer to an object of actual type A or B.

Tim - field hiding should be avoided anyway, as it is confusing/error-prone

TimTheEnchantora at 2007-7-12 20:11:38 > top of Java-index,Java Essentials,New To Java...
# 2
is it possible to do super.super.i ? im not sure
RockGuitar417a at 2007-7-12 20:11:38 > top of Java-index,Java Essentials,New To Java...