public abstract class PClass
{
public PClass()
{
Console.WriteLine("Parent");
}
public virtual void Fun()
{
Console.WriteLine("P.Fun()");
}
}
public class CClass:PClass
{
public CClass()
{
Console.WriteLine("Child");
}
public new void Fun()//如果是override则执行子类
{
Console.WriteLine("C.Fun()");
}
}
static void Main(string[] args)
{
PClass p = new CClass();
p.Fun();
Console.ReadLine();
}
输出内容:Parent Child P.Fun()