C#入门10.3——接口的实现和继承(2)

来源:互联网 发布:审计中数据透视表应用 编辑:程序博客网 时间:2024/06/06 07:03
static void Main(string[] args)        {            IFlyable[] flys = { new Sprraw(), new Eagle(), new Swan(), new Ballon() };            foreach (IFlyable outFlys in flys) outFlys.Fly();            Console.ReadKey();        }


 class Sprraw:Bird,IFlyable    {        public override void Eat()        {            Console.WriteLine("麻雀吃粮食");        }        public void Fly()        {            Console.WriteLine("麻雀会飞");        }    }


class Ostrich:Bird    {        public override void Eat()        {            Console.WriteLine("鸵鸟吃青草");        }            }


class Eagle:Bird,IFlyable    {        public override void Eat()        {            Console.WriteLine("老鹰吃小鸡");        }        public void Fly()        {            Console.WriteLine("鹰会飞");        }    }


abstract class Bird    {        public abstract void Eat();    }


class Swan:Bird,IFlyable    {        public override void Eat()        {            Console.WriteLine("天鹅吃鱼");        }        public void Fly()        {            Console.WriteLine("天鹅会飞");        }    }

class Ballon:IFlyable    {        public void Fly()        {            Console.WriteLine("气球会飞");        }    }


interface IFlyable    {        void Fly();    }



0 0
原创粉丝点击