可以调用基类的构造函数:- class Father
- {
- public Father() //无参的
- {
- }
- public Father(string Name) //有参的
- {
- this.name = Name;
- }
- string name;
- }
- class Son : Father
- {
- //增加一个属性
- public int Age{set;get;}
- //无参构造函数
- public Son(){}
- //带一个参数的构造函数,调用基类
- public Son(string Name):base(Name){}
- //新增一个构造函数
- public Son(string Name,int age):base(Name){this.Age=age;}
- }
- static void Main(string[] args)
- {
- Son s = new Son("张三");
- }
复制代码 |