继承小实验
2011-08-26 09:59 Carl Xing 阅读(177) 评论(0) 编辑 收藏 举报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()