• 面向对象之继承


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace 面向对象之继承
    {
        class Program
        {
            static void Main(string[] args)
            {
                //记者:我是记者,我的爱好是偷拍,我的年龄34,我是一个男的
                //程序员:我叫孙权  我的年龄23  我是男生  我的工作年限是3年
                Reporter rep = new Reporter("狗仔", 34, '', "偷拍");
                rep.ReporterSayhello();
                Programmer pro = new Programmer("孙权",23,'',3);
                pro.ProgrammerSayhello();
                Console.ReadKey();
            }
    
            public class person
            {
                private string _name;
    
                public string Name
                {
                    get { return _name; }
                    set { _name = value; }
                }
                private int _age;
    
                public int Age
                {
                    get { return _age; }
                    set { _age = value; }
                }
                private char _gender;
    
                public char Gender
                {
                    get { return _gender; }
                    set { _gender = value; }
                }
                public person(string name, int age, char gender)   // 声明一个父类的构造函数
                {
                    this.Name = name;
                    this.Age = age;
                    this.Gender = gender;
                }
    
            }
            public class Reporter : person
            {
                private string _hobby;
    
                public string Hobby
                {
                    get { return _hobby; }
                    set { _hobby = value; }
                }
    
                public Reporter(string name, int age, char gender, string hobby)
                    : base(name, age, gender)//声明继承父类。。
                {
                    this.Hobby = hobby;
                }
                public void ReporterSayhello()
                {
                    Console.WriteLine("我叫{0},我是一名记者,我的爱好是{1},我是{2}生,我今年{3}岁了", this.Name, this.Hobby, this.Gender, this.Age);
                }
    
            }
            public class Programmer : person
            {
                private int _WorkYear;
    
                public int WorkYear
                {
                    get { return _WorkYear; }
                    set { _WorkYear = value; }
                }
                public Programmer(string name, int age, char gender, int workyear)
                    : base(name, age, gender)
                {
                    this.WorkYear = workyear;
    
                }
                public void ProgrammerSayhello()
                {
                    Console.WriteLine("我叫{0},我是一名程序猿,我是{1}生,我今年{2}岁了,我的工作年限是{3}年", this.Name, this.Gender, this.Age, this.WorkYear);
    
                }
            }
        }
    }
  • 相关阅读:
    Read Table Binary Search读得field一定要按照Sort的顺序
    Retail Article Master Data 学习 (三) Reference Handling 和 Deviation
    像QQ一样的,好用的Navbar
    sql 脚本执行类
    Page.RegisterRequiresRaiseEvent()与Page.RegisterRequiresPostBack()方法
    ASP.Net实现文件的在线压缩和解压缩
    Word maker! 最大流dinic
    POJ 3258 River Hopscotch 二分查找
    C/C++浮点数在内存中的存储方式《转》
    opencv图像处理8卷积
  • 原文地址:https://www.cnblogs.com/kangshuai/p/4693333.html
Copyright © 2020-2023  润新知