.Net学习笔记----2015-07-16(C#基础复习02)

继承的复习

有效解决代码冗余,实现多态:增加代码的可扩展性,便于维护

1、单根性

2、传递性

子类并没有继承父类的构造函数,而是默认调用父类那个无参的构造函数

    class Program
    {
        static void Main(string[] args)
        {
        }
    }

    public class Person
    {
        //public Person()
        //{ }
        public Person(string name, int age, char gender)
        { }
        public string Name
        { get; set; }
        public int Age
        { get; set; }
        public char Gender
        { get; set; }
        public void CHLSS()
        { }
    }
    public class Student : Person
    {
        //在子类中调用父类的构造函数,使用关键字base
        public Student(string name, int age, char gender, int id)
            : base(name, age, gender)
        {
            this.ID = id;
        }
        //自动属性       
        public int ID
        { get; set; }

        public void CHLSS()
        {

        }
    }

    public class Teacher : Person
    {
        public Teacher(string name, int age, char gender, double salary)
            : base(name, age, gender)
        {
            this.Salary = salary;
        }
        public double Salary
        { get; set; }
        public void CHLSS()
        {

        }
    }

 

你可能感兴趣的:(.net)