请运用.net中对象的多态性技术展示猫咬和狗咬的动作。要求用C#代码实现。
namespace
ConsoleApplication1
{
interface animalBit
{
void bit();
}
class Program
{
static void Main(string[] args)
{
cats cat = new cats();
dogs dog = new dogs();
animalBit obj;
obj = cat;
obj.bit();
obj = dog;
obj.bit();
Console.ReadLine();
}
}
class cats:animalBit
{
animalBit Members#region animalBit Members
public void bit()
{
Console.WriteLine("cat bit");
}
#endregion
}
class dogs :animalBit
{
animalBit Members#region animalBit Members
public void bit()
{
Console.WriteLine("dog bit");
}
#endregion
}
}
vs2005实现
{
interface animalBit
{
void bit();
}
class Program
{
static void Main(string[] args)
{
cats cat = new cats();
dogs dog = new dogs();
animalBit obj;
obj = cat;
obj.bit();
obj = dog;
obj.bit();
Console.ReadLine();
}
}
class cats:animalBit
{
animalBit Members#region animalBit Members
public void bit()
{
Console.WriteLine("cat bit");
}
#endregion
}
class dogs :animalBit
{
animalBit Members#region animalBit Members
public void bit()
{
Console.WriteLine("dog bit");
}
#endregion
}
}