public class Test2A
{
int i = 1;
public virtual void M1()
{
Console.WriteLine("i am A");
}
public void M2()
{
Console.WriteLine("i = {0}",i);
}
}
public class Test2B : Test2A
{
int i = 2;
public override void M1()
{
Console.WriteLine("i am b");
}
public void M2()
{
Console.WriteLine("i = {0}", i);
}
}
Test2B b = new Test2B(); Test2A a = b; a.M1(); //M1被重写了,b的M1方法 a.M2(); //调用为a的M2方法 b.M1(); b.M2();