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

    三、截图

  • 相关阅读:
    剑指offer 合并两个排序的链表
    剑指offer 把字符串转换成整数
    剑指offer 数组中重复的数字
    剑指offer 数字在排序数组中出现的次数
    剑指offer 替换空格
    go学习笔记-错误处理
    go学习笔记-类型转换(Type Conversion)
    go学习笔记-语言指针
    go学习笔记-包处理
    go学习笔记-面向对象(Methods, Interfaces)
  • 原文地址:https://www.cnblogs.com/Lizhichengweidashen/p/14903860.html
Copyright © 2011-2022 走看看