Yes, Vidya is right.
When you have a reference type, the method call is resolved using
what the reference is pointing to, than the type of the reference itself. This, we all know, is commonly referred to as
Polymorphism. That is what is happening in the example. Though sup is of type Super, it is pointing to an instance of a Sub classtype. Hence the method on the Sub class type is invoked at runtime.
However, for variables and private methods, there is no polymorphism. The symbols and references are resolved at compile time using
the type of the reference rather than the type the reference is pointing to. Though sup is pointing to an instance of Sub, sup is declared as type Super. Hence the variable index in super is printed.
Hope this helps( better than my one line answer
)
Ajith
[This message has been edited by Ajith Kallambella (edited August 10, 2000).]