using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication4
{
interface ILiveBirth
{
string BabyCalled();//接口中的方法,返回string类型
}
class Animal { }
class Cat : Animal, ILiveBirth
{
string ILiveBirth.BabyCalled()
{ return "kitten"; }
}
class Dog : Animal, ILiveBirth
{
string ILiveBirth.BabyCalled()
{ return "wangwang"; }
}
class Bird : Animal,ILiveBirth
{
string ILiveBirth.BabyCalled()
{ return "我是一只小小鸟"; }
}
class Program
{
static void Main()
{
Animal[] animalArray = new Animal[3];//创建Animal数组
animalArray[0] = new Cat();
animalArray[1] = new Bird();
animalArray[2] = new Dog();
foreach (var a in animalArray)
{
ILiveBirth b = a as ILiveBirth;
if (b!=null)
{
Console.WriteLine("Baby is called:{0}", b.BabyCalled());
Console.ReadKey();
}
}
}
}
}