Originally posted by M Krishnan:
The above code prints "Base.print" while I was expecting the derived class' method to be called. why?
[ May 13, 2007: Message edited by: M Krishnan ]
[ May 14, 2007: Message edited by: M Krishnan ]
The thing to notice here is that you are calling the method printStr using a Base1 reference.
That means that even though the object is of runtime type Derived1, you can only call methods on the Base1 reference that are visible to the Base1 class.
In this case that means that the only method you can call on the reference is the method printStr defined in Base1 and inherited by Derived1.