zoukankan      html  css  js  c++  java
  • 关键字new

      1 using System;
      2 using System.Collections.Generic;
      3 using System.Linq;
      4 using System.Text;
      5 using System.Threading.Tasks;
      6 
      7 namespace _10关键字_new
      8 {
      9     class Program
     10     {
     11         static void Main(string[] args)
     12         {
     13             Reporter rep = new Reporter("记者", 11, '', "偷拍");
     14             rep.SayHello();
     15             rep.Test();
     16             
     17             Console.ReadKey();
     18         }
     19     }
     20 
     21     public class Person
     22     {
     23         private string _name;
     24         public string Name
     25         {
     26             get { return _name; }
     27             set { _name = value; }
     28         }
     29         private int _age;
     30         public int Age
     31         {
     32             get { return _age; }
     33             set { _age = value; }
     34         }
     35         private char _gender;
     36         public char Gender
     37         {
     38             get { return _gender; }
     39             set { _gender = value; }
     40         }
     41 
     42 
     43         public Person(string name, int age, char gender)
     44         {
     45             this.Name = name;
     46             this.Age = age;
     47             this.Gender = gender;
     48         }
     49 
     50         public void Test()
     51         {
     52             Console.WriteLine("测试");
     53         }
     54 
     55         public void SayHello()
     56         {
     57             Console.WriteLine("大家好,我是人类");
     58         }
     59     }
     60 
     61 
     62     public class Reporter : Person
     63     {
     64         public Reporter(string name, int age, char gender, string hobby)
     65             : base(name, age, gender)
     66         {
     67             this.Hobby = hobby;
     68         }
     69 
     70 
     71         private string _hobby;
     72 
     73         public string Hobby
     74         {
     75             get { return _hobby; }
     76             set { _hobby = value; }
     77         }
     78 
     79         public void ReporterSayHello()
     80         {
     81             Console.WriteLine("我叫{0},我是一名狗仔,我的爱好是{1},我是{2}生,我今年{3}岁了", this.Name, this.Hobby, this.Gender, this.Age);
     82         }
     83 
     84 
     85         public new void SayHello()
     86         {
     87             Console.WriteLine("大家好,我是记者");
     88         }
     89 
     90     }
     91 
     92 
     93     public class Programmer : Person
     94     {
     95         private int _workYear;
     96 
     97         public int WorkYear
     98         {
     99             get { return _workYear; }
    100             set { _workYear = value; }
    101         }
    102 
    103         public void ProgrammerSayHello()
    104         {
    105             Console.WriteLine("我叫{0},我是一名程序猿,我是{1}生,我今年{2}岁了,我的工作年限是{3}年", this.Name, this.Gender, this.Age, this.WorkYear);
    106         }
    107 
    108 
    109         public Programmer(string name, int age, char gender, int workYear)
    110             : base(name, age, gender)
    111         {
    112             this.WorkYear = workYear;
    113         }
    114 
    115 
    116         public new void SayHello()
    117         {
    118             Console.WriteLine("大家好,我是程序员");
    119         }
    120     }
    121 }
  • 相关阅读:
    IO
    多线程
    常用类
    异常
    接口
    面向对象
    面向对象
    学习数组
    for的嵌套循环
    XML:是什么?怎样工作的?可以做什么?将来的发展有会怎样?
  • 原文地址:https://www.cnblogs.com/liuslayer/p/4453673.html
Copyright © 2011-2022 走看看