可能重复:
C#:新建与覆盖
class BaseAppXmlLogReaders
{
public virtual void WriteLog() { }
public void Add()
{
}
}
class DerivedAppXmlLogReaders : BaseAppXmlLogReaders
{
public override void WriteLog()
{
}
public new void Add()
{ }
}
class Demo
{
public static void Main()
{
BaseAppXmlLogReaders obj = new DerivedAppXmlLogReaders();
obj.Add();//Call base class method
obj.WriteLog();//call derived class method
}
}
我有点困惑,但是它创建了 DerivedAppXmlLogReaders 的对象,但它调用了基类的 Add() 方法和派生类的 WriteLog() 方法。