protected override inherit problem

S

skidz

Hey all, I posted this question earlier, but made a big mess of it, so
posting again.

In the Program class below, when it executes testcall, the method
OverrideMe is called.

My problem is, when OverrideMe is called it is being executed the
method in the "A" class, not the "B" class, which is where I want it
to execute. What am I doing wrong, and how can I get the method in the
"B" class to execute instead?

public class A
{
protected virtual void OverrideMe()
{
throw new Exception("A.OverrideMe() must be overridden");
}
public void testcall()
{
OverrideMe();
}
}
public class B : A
{
protected override void OverrideMe()
{
Console.WriteLine("OverrideMe from B");
}
}
class Program
{
static void Main(string[] args)
{
B b=new B();
b.testcall();
Console.ReadLine();
}
}
 

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

Top