你的位置:首页 > 软件开发 > ASP.net > C# 面向对象——继承

C# 面向对象——继承

发布时间:2016-07-06 16:00:37
继承:代码文字结合理解class Program { static void Main(string[] args) { //Student s = new Student(); //Driver d = new Driver(); S ...

继承:代码文字结合理解

class Program  {    static void Main(get='_blank'>string[] args)    {      //Student s = new Student();      //Driver d = new Driver();      Student s = new Student("学生", 18, '男', 101);    }  }  /// <summary>  /// 父类——人类  /// </summary>  public class Person  {    private string _name;    public string Name    {      get { return _name; }      set { _name = value; }    }    private int _age;    public int Age    {      get { return _age; }      set { _age = value; }    }    private char _gender;    public char Gender    {      get { return _gender; }      set { _gender = value; }    }    public void CHLSS()    {      Console.WriteLine("吃喝拉撒睡");    }    public Person(string name, int age, char gender)    {      this.Name = name;      this.Age = age;      this.Gender = gender;    }    public Person()    {    }  }  /// <summary>  /// 子类——学生  /// </summary>  public class Student : Person  {    public Student(string name, int age, char gender, int id)      : base(name, age, gender)    {      //this.Name = name;      //this.Age = age;      //this.Gender = gender;      this.Id = id;    }    private int _id;    public int Id    {      get { return _id; }      set { _id = value; }    }    public void Study()    {      Console.WriteLine("学生会学习");    }  }  /// <summary>  /// 子类——老师  /// </summary>  public class Teacher :Person  {    public Teacher(string name, int age, char gender, double salary)      : base(name, age, gender)    {      this.Salary = salary;    }    private double _salary;    public double Salary    {      get { return _salary; }      set { _salary = value; }    }    public void Teach()    {      Console.WriteLine("老师会讲课");    }  }  /// <summary>  /// 子类——司机  /// </summary>  public class Driver:Person  {    public Driver(string name, int age, char gender, int driveTime)      : base(name, age, gender)    {      this.DirveTime = driveTime;    }    private int _dirveTime;    public int DirveTime    {      get { return _dirveTime; }      set { _dirveTime = value; }    }    public void Drive()    {      Console.WriteLine("司机会开车");    }  }

原标题:C# 面向对象——继承

关键词:C#

C#
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

可能感兴趣文章

我的浏览记录