i am Ok with output displayed for c1.dep() (overridden) , Could any one please explain me how exactly we get output in as 'A' and 'C' in line 1 and line 2 .
The revised version doesn't do what you say it does: -
The original version does do what you say: -
In the original, there is no overriding of any of the m1(something) methods. The three classes provide three different overloads of it.
The variable c1 is declared to contain an Az object. When choosing between overloads, it is the declared type that determines what happens. There is only one method in Az that matches c1.m1(c2); it's the one that prints "A".
In the modified version, the class Az has a method m1(Cz) that is overridden in class Cz. When choosing between overrides, it is the run-time type that matters. So, because c1's run-time type is Cz, the method in Cz is called, printing "C". [ August 20, 2007: Message edited by: Peter Chase ]
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Hi Peter , Thanks for replying . Here c1 has object which refer;s to "Cz" class. what you had mentioned in repy "The variable c1 is declared to contain an Az object" which comfuses me .
Please let me know if am wrong in understanding the concept.?