zoukankan      html  css  js  c++  java
  • interface

    interface Ishirou
        {       
            void Hunt();
        }
        interface Ishicao
        {
            void EatGrass();
        }
        abstract class Animal
        {
            public abstract void Eat();     
        }
        class Cat : Animal,Ishirou
        {
            public override void Eat() { Console.WriteLine("猫吃鱼"); }  
            public void Hunt()
            {
                Console.WriteLine("猫捉老鼠");           
            }
        }
        class Tiger : Animal, Ishirou
        {
            public override void Eat() { Console.WriteLine("老虎也吃鱼"); }
            public void Hunt()
            {
                Console.WriteLine("老虎捉羊");
            }
        }
        class Sheep : Animal, Ishicao
        {
            public override void Eat() { Console.WriteLine("羊吃草"); }  
            public void EatGrass()
            {          
            }
        }

        class Program
        {       
            static void Main(string[] args)
            {  
                List<Animal> animals = new List<Animal>();
                Animal a1 = new Cat();
                animals.Add(a1);
                Animal a2 = new Sheep();
                animals.Add(a2);
                Animal a3 = new Sheep();
                animals.Add(a3);
                Animal a4 = new Tiger();
                animals.Add(a4);          

                foreach (Animal a in animals)
                {
                    if (a is Ishirou)
                    {
                        Ishirou irou = (Ishirou)a;                    
                        irou.Hunt();
                    }
                }
                            
            }
        }
  • 相关阅读:
    软件工程的实践项目的自我目标
    transform使用导致元素内字体出现模糊的坑~~~
    nvmw安装,用于控制node版本;
    开章大吉~
    eclipse运行Android项目出现“The connection to adb is down, and a severe error has occured. You must restart adb and Eclipse. ”
    Date对象相关函数使用
    Balsamiq Mockups 注册码
    如何关闭sublime更新提示
    如何在边框中加入文字
    如何用手机测试移动端页面
  • 原文地址:https://www.cnblogs.com/imxh/p/2455636.html
Copyright © 2011-2022 走看看