zoukankan      html  css  js  c++  java
  • .NET程序设计——面向对象程序设计01

    一、任务

    1. 设计编写一个控制台应用程序,练习类的继承。

    (1) 编写一个抽象类 People,具有”姓名”,”年龄”字段,”姓名”属性,Work 方法。

    (2) 由抽象类 People 派生出学生类 Student 和职工类 Employer,继承 People 类,并

    覆盖Work 方法。

    (3) 派生类 Student 增加”学校”字段,派生类 Employer 增加”工作单位”字段。

    (4) 在 Student 和 Employer 实例中输出各自不同的信息。

    二、代码

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Text;
     4 
     5 namespace Tutorial2
     6 {
     7     public abstract class People
     8     {
     9         private string name;
    10         public int age;
    11 
    12         public string Name
    13         {
    14             get { return name; }
    15             set { name = value; }
    16             
    17         }
    18 
    19         public abstract void Work();
    20         
    21     }
    22 }
    People.CS
     1 using System;
     2 using System.Collections.Generic;
     3 using System.Text;
     4 
     5 namespace Tutorial2
     6 {
     7     public class Student:People
     8     {
     9         
    10         public  string school;
    11         
    12 
    13         public override void Work()
    14         {
    15             Console.WriteLine("我在学校学习.......");
    16         }
    17     }
    18 }
    Student.CS
     1 using System;
     2 using System.Collections.Generic;
     3 using System.Text;
     4 
     5 namespace Tutorial2
     6 {
     7     public class Employer:People
     8     {
     9         
    10         public  string workAdress;
    11         
    12 
    13         public override void Work()
    14         {
    15             Console.WriteLine("我在单位工作.......");
    16         }
    17     }
    18 }
    Employer.CS

    三、截图

  • 相关阅读:
    web自动化框架如何设计
    如何保证元素定位的成功率(等待机制)
    验证码问题处理
    selenium元素定位
    网路知识总结(session&&Cookie&&三次握手&&请求头)
    python中方法的总结
    Twelve Day 检测大写字母
    超过5名学生的课(SQL语句)
    The Eleven Day 删除排序数组中的重复项
    删除重复的电子邮箱(SQL语句)
  • 原文地址:https://www.cnblogs.com/Lizhichengweidashen/p/14903860.html
Copyright © 2011-2022 走看看