博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C# 继承与多态,相关关键字virtual、override、new
阅读量:2026 次
发布时间:2019-04-28

本文共 1156 字,大约阅读时间需要 3 分钟。

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace ConsoleApplication26{    class Program    {        static void Main(string[] args)        {            animal a = new animal();            a.name = "animal";            a.say();            cat c = new cat();            c.name = "cat";            c.say();            dog d = new dog();            d.name = "dog";            d.say();            sheep s = new sheep();            s.name = "sheep";            s.say();            animal a1 = new cat();            a1.say();            animal a2 = new dog();            a2.say();            animal a3 = new sheep();            a3.say();        }    }    class animal    {        public string name { get; set;}        public virtual void say()        {            Console.WriteLine("animal say");        }    }    class cat : animal    {        public override void say()        {            Console.WriteLine("cat say");        }    }    class dog : animal    {        public new void say()        {            Console.WriteLine("dog say");        }    }    class sheep : animal    {    }}

转载地址:http://ltdaf.baihongyu.com/

你可能感兴趣的文章
golang的数据类型之整型类型
查看>>
安装go版本
查看>>
golang的数据类型之基本数据类型的默认值和转换
查看>>
golang的数据类型之浮点类型
查看>>
golang的数据类型之字符串类型
查看>>
标识符
查看>>
scala函数
查看>>
Scala集合
查看>>
defer
查看>>
init函数和匿名函数
查看>>
函数参数的传递方式和变量作用域
查看>>
字符串函数
查看>>
面向对象之方法1
查看>>
kubeadm初始化kubernetes集群
查看>>
PythonStudy——线程中的几种消息队列
查看>>
PythonStudy——列表与字典推导式 List and dictionary derivation
查看>>
PythonStudy——字典的定义 Dictionary definition
查看>>
PythonStudy——格式化输入小练习
查看>>
PythonStudy——数字类型 Number type
查看>>
PythonStudy——列表操作 List operatio
查看>>