class Program
{
static void Main(string[] args)
{
B b = new B();
Console.ReadLine();
}
}
class A
{
public A()
{
Test();
}
public virtual void Test()
{ }
}
class B : A
{
int x = 1;
int y;
public B()
{
y = -1;
Test();
}
public override void Test()
{
Console.WriteLine("x={0},y={1}", x, y);
}
}输出什么?
B重新A的Test方法,调用B的构造函数,y=-1,输出结果:x=1,y=-1