I got this piece of code from Marcus Greens tutorial (Objective 6)
-----------------------------------------------
class Base {
int i=99;
public void amethod(){
System.out.println("Base.amethod()");
}
}
public class RType extends Base{
int i=-1;
public static void main(
String argv[]){
Base b = new RType(); //<= Note the type
System.out.println(b.i);
b.amethod();
}
public void amethod(){
System.out.println("RType.amethod()");
}
}
------------------------------------------
Note how the type of the reference is b Base but the type of actual class is RType.
The call to amethod will invoke the version in RType (ok, I get this, to do with late binding that I learned about at the campfire) but the call to output b.i will reference the field i in the Base class. (This is the bit I don't understand.)
Cath