Hello all,
I have a question related to object oriented programming as follows:-
Lets say I have a base class called BaseClass which has 2 methods Method1()
and Method2(). Also lets assume that Method1() has code that invokes
Method2()
Now lets say a new class called InheritedClass inherits BaseClass and
overrides Method2()
If I call InheritedClass.Method1() the which Method2() code will fire? The
one contained in BaseClass or the one contained in InheritedClass?
TIA!
Peter Duniho - 07 Aug 2007 19:41 GMT
> Lets say I have a base class called BaseClass which has 2 methods Method1()
> and Method2(). Also lets assume that Method1() has code that invokes
[quoted text clipped - 5 lines]
> If I call InheritedClass.Method1() the which Method2() code will fire? The
> one contained in BaseClass or the one contained in InheritedClass?
Assuming that Method2() is truly virtual, and thus can be truly
overridden, then for an instance of InheritedClass,
InheritedClass.Method2() will always be executed, even when called from
BaseClass.Method1().
That is, in fact, the point of virtual methods.
Pete
param@community.nospam - 08 Aug 2007 02:26 GMT
That is pretty sweet! :) Thanks
>> Lets say I have a base class called BaseClass which has 2 methods
>> Method1() and Method2(). Also lets assume that Method1() has code that
[quoted text clipped - 14 lines]
>
> Pete
sloan - 07 Aug 2007 20:36 GMT
Look at this design pattern as well.
http://www.dofactory.com/Patterns/PatternTemplate.aspx
As earlier said, "that is the point". ((<< not being a smart butt, but
yeah, that's kind of the kit and ka-boodle with it)))
> Hello all,
>
[quoted text clipped - 11 lines]
>
> TIA!