示例#1
0
        public static void Main(String[] args)
        {
            //  Create animals
            Animal       a  = new Animal(3, 3);
            Cat          g  = new Cat(1, 2);
            MutantParrot lM = new MutantParrot(3, 3);

            //  Static list
            Animal[] farm = new Animal[3];
            farm[0] = a;
            farm[1] = g;
            farm[2] = lM;

            foreach (Animal ani in farm)
            {
                Console.WriteLine(ani.Talk);
            }

            //  Dynamic list
            LinkedList <Animal> lorry = new LinkedList <Animal>();

            lorry.AddLast(a);
            lorry.AddLast(g);
            lorry.AddLast(lM);
            //  New for
            foreach (Animal o in lorry)
            {
                Console.WriteLine(o.Talk);
            }
        }
示例#2
0
        public static void main(String[] args)
        {
            Animal       a  = new Animal(3, 3);
            Dog          p  = new Dog(1, 1, true);
            Cat          g  = new Cat(1, 2);
            Parrot       l  = new Parrot(1, 2);
            MutantParrot lM = new MutantParrot(3, 3);


            Console.WriteLine("ANIMAL: " + a.Talk);
            Console.WriteLine("DOG: " + p.Talk);
            Console.WriteLine("CAT: " + g.Talk);
            Console.WriteLine("PARROT: " + l.Talk);
            Console.WriteLine("MUTANT PARROT:" + lM.Talk);


            a = p;
            Console.WriteLine("ANIMAL: " + a.Talk);


            a = lM;
            Console.WriteLine("ANIMAL: " + a.Talk);
        }