Hi Rekha,
Dynamic Binding rules do not apply to instance variables. When you access an instance variable directly (ie not through a method); the declared type is used.
The declared type of the object
sup is
Super so when the reference <code>sup.index</code> is resolved
Java checks the Super class for the instance variable 'index' and returns it's value, 5.
When you invoke the method <code>sup.printVal()</code> Java checks the Runtime type of the object, which is
Sub. It invokes the <code>printVal()</code> method in the Sub class. The <code>printVal()</code> references the variable 'index'. Java checks to see if there is a variable 'index' in the same class. There is so it uses it's value '2'.
Hope that helps.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform