G
Guest
In the following code, calling CallTestMethod() from an instance of the
derived class (the base is abstract and we can never instantiate it),
referencing 'base.TestMethod()' actually calls 'TestMethod()' in the base
class, but referencing 'this.CallTestMethod()' (defined in the base class)
references the overriding method, not the method defined within the base
class, making calling 'TestMethod()' seem virtually impossible (pun intended).
So my question is: Is there another way to call a virtual method defined in
the base class from the base class itself?
(note: I know that a work-around is to put the code from the virtual method
into another method and call that, but I am asking the question to understand
the language better.)
abstract public class TestObjectBase
{
virtual public void TestMethod()
{
// do stuff
}
public string CallTestMethod()
{
TestMethod(); // calls the method from the derived class
this.TestMethod(); // also call the method from the derived class
// Question: Is there any way to call the TestMethod defined above?
}
} // end of class
public class TestObject : TestObjectBase
{
public override void TestMethod() {
// do other stuff
}
public void CallBaseTestMethod() {
base.TestMethod(); // this references the method defined in the
base class
}
}
derived class (the base is abstract and we can never instantiate it),
referencing 'base.TestMethod()' actually calls 'TestMethod()' in the base
class, but referencing 'this.CallTestMethod()' (defined in the base class)
references the overriding method, not the method defined within the base
class, making calling 'TestMethod()' seem virtually impossible (pun intended).
So my question is: Is there another way to call a virtual method defined in
the base class from the base class itself?
(note: I know that a work-around is to put the code from the virtual method
into another method and call that, but I am asking the question to understand
the language better.)
abstract public class TestObjectBase
{
virtual public void TestMethod()
{
// do stuff
}
public string CallTestMethod()
{
TestMethod(); // calls the method from the derived class
this.TestMethod(); // also call the method from the derived class
// Question: Is there any way to call the TestMethod defined above?
}
} // end of class
public class TestObject : TestObjectBase
{
public override void TestMethod() {
// do other stuff
}
public void CallBaseTestMethod() {
base.TestMethod(); // this references the method defined in the
base class
}
}