Well firstof all my name is Anupam Sinha and not Anupama. The overridden method that will be invoked is decided at runtime and for overloaded methods it is decided at compile time. So now the simple rule is that a superclass reference var refering to subclass type will call the subclass method if the subclass inherits it. In simple terms you can say that it will be simply the superclass's method in case the subclass doesn't overrides it. But I guess what actually happens is when the subclass doesn't overrides it then the subclass inherits(if inheritable) the superclass method which is then called.
But what if as in your code the method can not be inherited then the method which the superclass has is executed.
But its not the other way round. That is a superclass reference var refering to subclass type can
not refer to a method that the superclass does not have. That is you can not refer to subclass method using a superclass var type if the superclass does not has that method. The compiler will check to see at compiletime whether or not the method being refered to by the class type var is actually a method of that class.
I guess that should help.
As for your question "can a overridden method of Sub be called from Superclass reference. "
I guess overriden is the wrong
word it should be overriding. If that is what you meant the answer is yes infact only an overriding method of Subclass be called from Superclass reference.
[ May 15, 2003: Message edited by: Anupam Sinha ]