public class Runner3 {
public static void main(
String[] args) {
Base b = new Derived();
Derived d = new Derived();
System.out.println(b.id);
System.out.println(d.id);
}
}
class Base
{
String id = "i am base";
}
class Derived extends Base
{
String id = "i am derived";
}
output.....
i am base
i am derived
above prg suggest that field access depends upon refernece type not upon actual object created.
and this reference is implicitly passed...in base class this(reference) is of type of base(since base class has no idea about derived class)though it is pointing to object of subclass..that is the reason hidden field is printed...
PLEASE LET ME KNOW IF I AM WRONG.....
[ June 14, 2005: Message edited by: rajan singh ]