标签:
class Program { static void Main(string[] args) { ParentClass test = new SubClass(); test.doSomething(); /*结果: ParentClass SubClass doSomething in ParentClass */ } } class ParentClass { public ParentClass() { Console.WriteLine("ParentClass"); } public virtual void doSomething() { Console.WriteLine("doSomething in ParentClass"); } } class SubClass:ParentClass { public SubClass() { Console.WriteLine("SubClass"); } public new void doSomething() { Console.WriteLine("doSomething in SubClass"); } }
class Program { static void Main(string[] args) { ParentClass test = new SubClass(); test.doSomething(); /* 结果: ParentClass SubClass doSomething in SubClass */ } } class ParentClass { public ParentClass() { Console.WriteLine("ParentClass"); } public virtual void doSomething() { Console.WriteLine("doSomething in ParentClass"); } } class SubClass:ParentClass { public SubClass() { Console.WriteLine("SubClass"); } public override void doSomething() { Console.WriteLine("doSomething in SubClass"); } }
标签:
原文地址:http://www.cnblogs.com/jane850113/p/5039529.html