using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace 继续 { public class Person { public string Name { get; set; } public int Age { get; set; } public virtual void SayHello() { Console.WriteLine("我的名字是:{0},年龄是{1}",Name,Age); } } //声明中国人类,继承Person类 public class Chinese:Person { public override void SayHello() { base.SayHello(); } } class Program { static void Main(string[] args) { Chinese c1 = new Chinese(); c1.Name = "老张"; c1.Age = 40; c1.Age++; //年龄加1 //对象是引用类型,所以老李的年龄也应该加1 Chinese c2 = c1; c2.Name = "老李"; c2.SayHello(); } } }