• 练习:C# -- 多态


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace 多态
    {
        class Program
        {
            static void Main(string[] args)
            {
                /*
                 练习:
                 真的鸭子嘎嘎叫
                 木头鸭子吱吱叫
                 橡胶鸭子唧唧叫
                 */
                RealDark rrd = new RealDark();
                WoodenDark wd = new WoodenDark();
                RubberDark rd = new RubberDark();
    
                Dark[] d = { rrd, wd, rd };
                for (int i = 0; i < d.Length; i++)
                {
                    d[i].Bark();
                }
                Console.ReadLine();
            
    
                /*
                 练习:
                 经理10点打卡
                 员工9点打卡
                 程序员不打卡
                 */
                Employee em = new Employee();
                Manager ma = new Manager();
                Programmer pr = new Programmer();
                Employee[] ee = { em, ma, pr };
                for (int i = 0; i < ee.Length; i++)
                {
                    ee[i].daka();
                }
                Console.ReadLine();
            
            }
        }
    }
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace 多态
    {
    
        public class Dark
        {
            public virtual void Bark()
            {
                Console.WriteLine("我是鸭子");
            }
        }
    
        public class RealDark : Dark
        {
            public override void Bark()
            {
                Console.WriteLine("真的鸭子嘎嘎叫~");
            }
        }
    
        public class WoodenDark : Dark
        {
            public override void Bark()
            {
                Console.WriteLine("木头鸭子吱吱叫~");
            }
        }
    
        public class RubberDark : Dark
        {
            public override void Bark()
            {
                Console.WriteLine("橡胶鸭子唧唧叫~");
            }
        }
    
    
    
        public class Employee
        {
            public virtual void daka()
            {
                Console.WriteLine("员工9点打卡");
            }
        }
    
        public class Manager : Employee
        {
            public override void daka()
            {
                Console.WriteLine("经理10点打卡");
            }
        }
    
        public class Programmer : Employee
        {
            public override void daka()
            {
                Console.WriteLine("程序员不打卡");
            }
        }
    
    }
  • 相关阅读:
    软工随堂小测——四则运算
    K米测评
    uml用例图
    第二次结对编程作业——毕设导师智能匹配
    原型设计与需求分析
    散列函数的应用及其安全性
    Think In Java读书笔记:内部类覆盖及其初始化
    如何在服务器(centOS系统)上运行JavaWeb项目
    结对工程作业
    《构建之法》——第四、第十七章
  • 原文地址:https://www.cnblogs.com/xiao55/p/5598397.html
Copyright © 2020-2023  润新知