日期:2014-05-18 浏览次数:20747 次
public class Person { private string _personName; public string PersonName { get; set; } private int _age; public int Age { get; set; } public Person() { } public Person(string personname, int age) { this._personName = personname; this._age = age; } public virtual void WriteInfo() { Console.WriteLine(this._personName + ":" + this._age); } } public class Teacher : Person { private string _university; public string University { get; set; } public Teacher() : base() { } public Teacher(string university):base("张三", 30) { this._university = university; } public virtual void WriteInfo() { Console.WriteLine(this._university); } } 使用 Person person = new Person(); person.Age = 100; person.WriteInfo(); person.PersonName = "李四"; person = new Person("王五", 40); person.WriteInfo(); Teacher teacher = new Teacher(); teacher.University = "北京大学"; teacher.Age = 50; teacher.PersonName = "赵六"; teacher.WriteInfo(); teacher = new Teacher("清华大学"); teacher.WriteInfo();