posted 19 years ago
Hi Madhur:
Please note following:
1. eat() is NOT overridding in derived classes as arguments are of different types in each eat().
2. h is of M type but holds C type object.
3. h.eat(c) is passing C type object to eat method. That particular method ( eat(C c) ) is not available in M. As it is not in super class (i.e. M), the derived class's ( eat(C c) ) method can not be called.
4. Now M has a method with same name but different argument type. Therefore, that method ( eat(M m) ) is closest to call i.e. ( eat(C c) and it will be invoked. And you get mammal output.
Hope this helps.
Barkat
[ September 11, 2002: Message edited by: Barkat Mardhani ]
[ September 11, 2002: Message edited by: Barkat Mardhani ]