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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top