oop question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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!
 
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?

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
 
That is pretty sweet! :) Thanks

Peter Duniho said:
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
 
Back
Top