C#继承(二)
base关键
base指得是父类对象。
1,如果base放在子类构造函数后,则base调用的是父类的构造函数。
2,如果base在普通方法中,则指的是创建的父类对象,可以调用父类对象中的方法和属性。
View Code
1 using System; 2 public class StudyExtend1 3 { 4 public static void Main() 5 { 6 People p = new People("ss"); 7 8 } 9 } 10 public class WuDang 11 { 12 13 private string name; 14 public WuDang(){} 15 public WuDang(string name) 16 { 17 Console.WriteLine("I'm First!"); 18 } 19 public WuDang(int age){ 20 Console.WriteLine("I'm First!"); 21 } 22 public WuDang(string name,int age) 23 {} 24 public string Name 25 { 26 get{return this.name;} 27 set{this.name = value;} 28 } 29 public void Taiji() 30 { 31 Console.WriteLine(this.name); 32 Console.WriteLine(this.GetType()); 33 } 34 } 35 //People继承了武当 36 public class People : WuDang 37 { 38 public People(string name):base("ss",67) 39 { 40 41 Console.WriteLine("I'm Second!"); 42 } 43 }