protected override inherit problem

  • Thread starter Thread starter skidz
  • Start date Start date
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();
}
}
 
Back
Top