问答详情
源自:2-4 构造函数

老师源代码谁有吗?

哪位大哥,把老师的源码复制一下给我看看,谢谢了

提问者:韩亚强 2019-06-23 10:42

个回答

  • 眉眉眉
    2019-06-30 20:43:55

    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();
       }
       


      }
     }