Esempio n. 1
0
        static void Main(string[] args)
        {
            Pet[] pets = new Pet[] { new Dog("Wangcai"), new Cat("Xiaoming"), new Dog("xiaoPeng") };

            //也可以使用基类的引用,只能调用基类中的方法
            //Pet dog2 = new Dog("xxx");

            for (int i = 0; i < pets.Length; i++)
            {
                pets[i].Speak();
            }
            Console.ReadKey();
            Cat         xiaoming    = new Cat("xiaoming");
            ICatchMouse icatchmouse = (ICatchMouse)xiaoming;
            IClimbTree  iclimbtree  = (IClimbTree)xiaoming;

            //通过对象调用
            xiaoming.CatchMouse();
            xiaoming.ClimbTree();

            //通过接口调用
            icatchmouse.CatchMouse();
            iclimbtree.ClimbTree();
            Console.ReadKey();

            //调用静态方法
            Dog.ShowNum();
            Console.ReadKey();

            //使用静态类扩展的方法
            Dog dog = new Dog("ergouzi");

            dog.HowToFeedDog();
            Console.ReadKey();
        }
Esempio n. 2
0
 public static void catchTask(ICatchMouse c)
 {
     c.Catch();
 }