1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| namespace code_1 { class Program { static void Main(string[] args) { Person person = new Person(); Console.WriteLine("Person类的Print方法打印内容"); person.Print(); Student student = new Student(); Console.WriteLine("Student类的Print方法打印内容"); student.Print(); Teacher teacher = new Teacher(); Console.WriteLine("Teacher类的Print方法打印内容"); teacher.Print(); } } class Person { public int Id { get; set; } public string Name { get; set; } public string Sex { get; set; } public string Cardid { get; set; } public string Tel { get; set; } public void Print() { Console.WriteLine("编号:" + Id); Console.WriteLine("姓名:" + Name); Console.WriteLine("性别:" + Sex); Console.WriteLine("身份证号:" + Cardid); Console.WriteLine("联系方式:" + Tel); } } class Student : Person { public string Major { get; set; } public string Grade { get; set; } public void Print() { Console.WriteLine("专业:" + Major); Console.WriteLine("年级:" + Grade); } } class Teacher { public string Title { get; set; } public string WageNo { get; set; } public void Print() { Console.WriteLine("职称:" + Title); Console.WriteLine("工资号:" + WageNo); } } }
|