C# 接口


using
System; class testInterface { // class Bird { public void Run() { Console.WriteLine("鸟在奔跑!"); } } //接口 public interface IFlyable { //接口和抽象类一样,也是只能有方法的声明,不能有任何的实现 void Fly(); } //麻雀 class Sparrow : Bird, IFlyable { #region IFlyable 成员 public void Fly() { Console.WriteLine("小麻雀飞在树林中。"); } #endregion } //鹦鹉 class Parrot : Bird, IFlyable { #region IFlyable 成员 public void Fly() { Console.WriteLine("鹦鹉在小笼子里飞..."); } #endregion } //企鹅 class Penguin : Bird { } static void Main() { IFlyable fly = new Parrot(); fly.Fly(); } }

Output:

鹦鹉在小笼子里飞...

posted @ 2013-10-30 20:13  petercao  阅读(458)  评论(0编辑  收藏  举报