标签:
class Person { public Person() { Console.WriteLine("========================"); } public Person(string name, int age, string email) { this.Name = name; this.Age = age; this.Email = email; } public string Name { get; set; } public int Age { get; set; } public string Email { get; set; } }
class Teacher : Person { public Teacher(string name, int age, string email, double salary) : base(name, age, email) { //this.Name = name; //this.Age = age; //this.Email = email; this.Salary = salary; } public double Salary { get; set; } }
这样是调用父类中第二个有参的构造函数,如果去掉Base默认调用无参构造函数
注意执行顺序是:先调用父类的构造函数,然后再执行子类自己的构造函数。
标签:
原文地址:http://www.cnblogs.com/xiaoshi212/p/4556190.html