call intermediate class method

  • Thread starter Thread starter G. Stewart
  • Start date Start date
G

G. Stewart

Given the following scenario:

class Base1
{
protected virtual void Method1()
{
}
}

class Derived1 : Base1
{
protected override void Method1()
{
// do stuff
base.Method1();
}
}


class Derived2 : Derived1
{
protected override void Method1()
{
base.Method1() // this calls Method1 of Base1
// how to call Method1 of Derived1??
}
}


How would I call the overriden method of the intermediate derived
class (i.e. Method1 or Derived1) from the secondarily derived class,
Derived2?

Thanks.
 
When a call is made to Method1 on Derived2, the command "base.Method1();"
calls into Derived1's Method1. This is because Derived2 is derived from
Derived1 which means that its base class is Derived1. Then, when Derived1
calls "base.Method1()" the code in Base1.Method1() is executed.

Ben Lucas
Lead Developer
Solien Technology, Inc.
www.solien.com
 
Back
Top