Пример #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            BlackBear  blackBear  = new BlackBear();
            Coho       coho       = new Coho();
            GreyWolf   greyWolf   = new GreyWolf();
            LionFish   lionFish   = new LionFish();
            PinkSalmon pinkSalmon = new PinkSalmon();
            PolarBear  polarBear  = new PolarBear();



            Console.WriteLine(polarBear.Swim());
            Console.WriteLine(pinkSalmon.Eat());
            Console.WriteLine(blackBear.Nurse());
            Console.WriteLine(lionFish.Sleep());
            Console.WriteLine(greyWolf.Play());
            Console.WriteLine(coho.Migrate());

            IRun bBear = new BlackBear();

            Console.WriteLine(bBear.TopSpeed);

            Console.WriteLine(greyWolf.Run());
            Console.WriteLine(pinkSalmon.EatsBugs());
            Console.WriteLine(pinkSalmon.favoriteBug);
            Console.WriteLine(blackBear.favoriteBug);
            Console.WriteLine(blackBear.EatsBugs());
        }
Пример #2
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Welcome to my zoo!\n");
            Console.WriteLine("My zoo has an abstract base class called Mammal.\nMammals" +
                              " have 1) an abstract name and 2) an abstract age, and can 1) eat (abstract) and 2) make a sound (virtual).\n");

            Console.WriteLine("\n\nHit <ENTER> to continue.");
            Console.ReadLine();

            //Show info about Bears and demo different Bear subclasses
            Console.WriteLine("The class 'Bear' inherits from Mammal and overrides all properties and methods. Bear additionally" +
                              " adds a virtual property called ClawLength and an abstract method called Hunts().\n");
            Console.WriteLine("There are three Bear descendent classes: Panda, Grizzly, and PolarBear.");
            Console.WriteLine("Pandas, Grizzlies, and PolarBears override all properties and methods of Bear EXCEPT for: ClawLength, Age, and Sound.");
            Bear[] myBears = CreateBears();

            Console.WriteLine("\n\nHit <ENTER> to see a demonstration of each class that inherits from Bear.");
            Console.ReadLine();
            Console.WriteLine("Here's a demonstration of each bear type\n");
            ShowBears(myBears);
            Console.WriteLine("\n\nHit <ENTER> to continue.");
            Console.ReadLine();


            //Instantiate Primates and return collection of primates
            Console.WriteLine("The class 'Primate' inherits from Mammal and overrides all properties and methods. Primate additionally" +
                              " adds a virtual property called HasTail and an virtual method called Hangs().\n");
            Console.WriteLine("There are three Primate descendent classes: Lemur, Chimpanzee, and Proboscis.");
            Console.WriteLine("Lemurs and Proboscii override Name, Eats(), Sound(), while Chimpanzees additionally override HasTail. ");
            Primate[] myPrimates = CreatePrimates();
            Console.WriteLine("\n\nHit <ENTER> to see a demonstration of each class that inherits from Primate.");
            Console.ReadLine();
            Console.WriteLine("Here's a demonstration of each primate type\n");
            ShowPrimates(myPrimates);
            Console.WriteLine("\n\nHit <ENTER> to continue.");
            Console.ReadLine();

            //Show RingTailed
            Console.WriteLine("Additionally, the class RingTailed inherits from Lemur and adds a method called SpendsTime()");
            RingTailed ringTailedLemur = new RingTailed();

            Console.WriteLine($"Name: {ringTailedLemur.Name}");
            Console.WriteLine($"Age: {ringTailedLemur.Age}");
            Console.WriteLine($"Has tail? {ringTailedLemur.HasTail}");
            Console.WriteLine($"Eats: {ringTailedLemur.Eats()}");
            Console.WriteLine($"Sound: {ringTailedLemur.Sound()}");
            Console.WriteLine($"Hangs: {ringTailedLemur.Hangs()}");
            Console.WriteLine($"Spends time: {ringTailedLemur.SpendsTime()}");
            Console.WriteLine();

            //Show Interface Implementation
            Console.WriteLine("Finally, there are two interfaces: ICanSwim and ICanGroom.");
            Console.WriteLine("Chimpanzee implements both, while PolarBear implements ICanSwim");
            Console.WriteLine("\n\nHit <ENTER> to see a demonstration.");
            Console.ReadLine();
            PolarBear  pb = new PolarBear();
            Chimpanzee c  = new Chimpanzee();

            Console.WriteLine($"calling PolarBear.Swim(): {pb.Swim()}");
            Console.WriteLine($"calling PolarBear.DryOff(): {pb.DryOff()}");
            Console.WriteLine($"calling Chimpanzee.Swim(): {c.Swim()}");
            Console.WriteLine($"calling Chimpanzee.DryOff(): {c.DryOff()}");
            Console.WriteLine($"calling Chimpanzee.Groom(): {c.Groom()}");
            Console.WriteLine($"calling Chimpanzee.EatFoundBug: {c.EatFoundBug()}");
        }
Пример #3
0
        public static string PolarSwims()
        {
            PolarBear p = new PolarBear();

            return(p.Swim());
        }