class Super
{ int index = 5;
public void printVal()
{ System.out.println( "Super" );
}
}
class Sub extends Super
{ int index = 2;
public void printVal()
{ System.out.println( "Sub" );
}
}
public class Runner
{ public static void main(
String argv[] )
{ Super sup = new Sub();
System.out.print( sup.index + "," );
sup.printVal();
}
}
Output: 5, Sub
Why does sup.index ref to value i in Super class? I thought being that my instance reference refers to an instance object of Sub() that it would display the value held in Sub i=2.
Can some one explain?
