zoukankan      html  css  js  c++  java
  • 一个继承例子

      1 using System;
      2 using System.Collections.Generic;
      3 using System.Linq;
      4 using System.Text;
      5 using System.Threading.Tasks;
      6 
      7 namespace _08继承
      8 {
      9     class Program
     10     {
     11         static void Main(string[] args)
     12         {
     13             //Student s = new Student();
     14 
     15             //Driver d = new Driver();
     16             Student s = new Student("学生", 18, '', 101);
     17         }
     18     }
     19 
     20     public class Person
     21     {
     22         private string _name;
     23 
     24         public string Name
     25         {
     26             get { return _name; }
     27             set { _name = value; }
     28         }
     29 
     30         private int _age;
     31 
     32         public int Age
     33         {
     34             get { return _age; }
     35             set { _age = value; }
     36         }
     37 
     38         private char _gender;
     39 
     40         public char Gender
     41         {
     42             get { return _gender; }
     43             set { _gender = value; }
     44         }
     45 
     46         public void CHLSS()
     47         {
     48             Console.WriteLine("吃喝拉撒睡");
     49         }
     50 
     51 
     52 
     53         public Person(string name, int age, char gender)
     54         {
     55             this.Name = name;
     56             this.Age = age;
     57             this.Gender = gender;
     58         }
     59 
     60         //public Person()
     61         //{
     62 
     63         //}
     64 
     65 
     66     }
     67     public class Student : Person
     68     {
     69 
     70         public Student(string name, int age, char gender, int id)
     71             : base(name, age, gender)
     72         {
     73             //this.Name = name;
     74             //this.Age = age;
     75             //this.Gender = gender;
     76             this.Id = id;
     77         }
     78 
     79 
     80         private int _id;
     81 
     82         public int Id
     83         {
     84             get { return _id; }
     85             set { _id = value; }
     86         }
     87 
     88 
     89 
     90         public void Study()
     91         {
     92             Console.WriteLine("学生会学习");
     93         }
     94     }
     95     public class Teacher :Person
     96     {
     97 
     98         public Teacher(string name, int age, char gender, double salary)
     99             : base(name, age, gender)
    100         {
    101             this.Salary = salary;
    102         }
    103 
    104         private double _salary;
    105         public double Salary
    106         {
    107             get { return _salary; }
    108             set { _salary = value; }
    109         }
    110         public void Teach()
    111         {
    112             Console.WriteLine("老师会讲课");
    113         }
    114     }
    115     public class Driver:Person
    116     {
    117 
    118         public Driver(string name, int age, char gender, int driveTime)
    119             : base(name, age, gender)
    120         {
    121             this.DirveTime = driveTime;
    122         }
    123 
    124 
    125         private int _dirveTime;
    126         public int DirveTime
    127         {
    128             get { return _dirveTime; }
    129             set { _dirveTime = value; }
    130         }
    131         public void Drive()
    132         {
    133             Console.WriteLine("司机会开车");
    134         }
    135     }
    136 
    137 
    138 
    139 }
  • 相关阅读:
    java分解质因数
    GUID全局唯一标识符
    Oracle-教师信息表(Teacher)
    Oracle-成绩表(Score)
    Oracle-建表course
    Oracle-建表student
    输入输出-复制
    Map
    哈希
    链表
  • 原文地址:https://www.cnblogs.com/liuslayer/p/4453630.html
Copyright © 2011-2022 走看看