惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Stack Overflow Blog
Stack Overflow Blog
云风的 BLOG
云风的 BLOG
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Recent Announcements
Recent Announcements
Microsoft Security Blog
Microsoft Security Blog
Microsoft Azure Blog
Microsoft Azure Blog
J
Java Code Geeks
D
DataBreaches.Net
U
Unit 42
P
Proofpoint News Feed
I
InfoQ
Apple Machine Learning Research
Apple Machine Learning Research
Google DeepMind News
Google DeepMind News
博客园 - Franky
博客园_首页
IT之家
IT之家
博客园 - 叶小钗
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 【当耐特】
Hugging Face - Blog
Hugging Face - Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
阮一峰的网络日志
阮一峰的网络日志

博客园 - 言午

Nopcommerce 二次开发2 Admin Nopcommerce 二次开发1 基础 Nopcommerce 二次开发2 WEB Nopcommerce 二次开发0 sqlce中不支持sp_rename修改表名 C#读取Excel遇到无法读取的解决方法 狼奔代码生成器 银行账户类 累 抽象类 抽象方法 Message 类的继承 多态(虚方法) 事件event 委托 代理 索引! 第五周作业 第四周作业 考试! 线程安全 二 线程安全 一
interface
言午 · 2012-04-18 · via 博客园 - 言午

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();
                }
            }
                        
        }
    }