abstract class BaseClass
{
public virtual void MethodA()
{
Console.WriteLine("BaseClass");
}
public virtual void MethodB(){}
}
class Class1:BaseClass {
public void MethodA(){
Console.WriteLine("Class1");
}
public override void MethodB(){}
}
class Class2:Class1 {
new public void MethodB()
}
class MainClass {
public static void Main(string[] args)
{
Class2 o=new Class2();
o.MethodA();
BaseClass b = 0;
b.MethodA();
}
}
输出为class1和BaseClass因为在class1中方法MethodA没被override