韩亚强
2019-06-23 10:42
哪位大哥,把老师的源码复制一下给我看看,谢谢了
class Pet
{
interface Iclimbtree
{
void climbtree();
}
interface Icatchmice
{
void catchmice();
}
public Pet(string name)
{
Name = name;
}
protected string Name;
virtual public void printf()
{
Console.WriteLine(Name);
}
public class Dog:Pet,Icatchmice,Iclimbtree
{
public void catchmice()
{
Console.WriteLine(" " + Name + "catch");
}
public void climbtree()
{
Console.WriteLine(" " + Name + "tree");
}
public Dog(string name):base(name)
{
}
override public void printf()
{
Console.WriteLine("mmm" + Name+"lll");
}
}
public class Cat : Pet
{
public Cat(string name):base(name)
{
}
override public void printf()
{
Console.WriteLine("mmm" + Name + "222");
}
}
}
class Program
{
static void Main(string[] args)
{
/*Pet dog1 = new Dog();
dog1.Name = "eat";
dog1.printf();
Pet cat1 = new Cat();
cat1.Name = "drink";
cat1.printf();*/
Pet[] pets = new Pet[] { new Dog("aaa"), new Cat("bbb") };
for(int i=0;i<=pets.Length;i++)
{
pets[i].printf();
}
Cat cat1 = new Cat("Tom2");
if(cat1 is Iclimbtree)
{
Iclimbtree cat = (Iclimbtree)cat1;
cat.Iclimbtree();
}
}
}
C#面向对象编程
68856 学习 · 153 问题
相似问题