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();
}
}
The above question is from:
MindQ_s_Sun_Certified_Java_Programmer_Practice_Test.htm
ans: (5, super)
It is unclear to me that that method from subclass
is executed.But the value is sup.index as expected.