zoukankan      html  css  js  c++  java
  • 继承 多态

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace 继承_多态
    {
        class Ren
        {
            private string _Name;
    
            public string Name
            {
                get { return _Name; }
                set { _Name = value; }
            }
            private string _Sex;
    
            public string Sex
            {
                get { return _Sex; }
                set { _Sex = value; }
            }
            private DateTime _Birthday;
    
            public DateTime Birthday
            {
                get { return _Birthday; }
                set { _Birthday = value; }
            }
    
            private string _Nation;
    
            public string Nation
            {
                get { return _Nation; }
                set { _Nation = value; }
            }
    
        }
    }

    继承:
    访问修饰符    class    类名 :类名

    一个类只能有一个父类(亲爹)

    父类 某个类继承自某个类
    子类 派生类 超类

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace 继承_多态
    {
        class XueSheng : Ren
        {
         
    
        }
    }
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace 继承_多态
    {
        class Program
        {
            static void Main(string[] args)
            {
               ren r = new ren();
               xuesheng xs = new ren();
               xs.//可以搜出在class ren中写的name  sex  birthday
    
                Console.ReadLine();
            }
        }
    }
    

    多态:
    类的多种形态

    父类存在虚方法           virtual
    子类重写                  override

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace 继承_多态
    {
        class Fly
        {
            public virtual string Flying()//不加virtual其他class不能用flying
            {
                return "我会飞!!!";
            }
    
    
        }
    }

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace 继承_多态
    {
        class Bird : Fly
        {
            public override string Flying()//需要加override才能用
            {
                return "拍拍翅膀我就能飞!!!";
            }
    
    
    
        }
    }
    
    
    
     
  • 相关阅读:
    02 日志系统: 一条SQL 更新语句是如何执行的
    MySql 实战45讲笔记 : 01
    爬取boss直聘全国招聘数据并做可视化
    爬取豆瓣电影-长津湖短评
    尝试破解压缩文件
    将webp格式的图像批量转化成jpg
    将JPG格式图片转换成PNG格式
    几个学习编程的游戏网站
    检测网址连接有效性
    监控设备电池电量并发送通知
  • 原文地址:https://www.cnblogs.com/liuyubin0629/p/7097496.html
Copyright © 2011-2022 走看看