Exemplo n.º 1
0
        // Method which prints out several properties and methods of the Batman Class
        public static void DisplayBatman()
        {
            Console.WriteLine(
                "Here is Batman, he is derived from the " +
                "Animal -> Mammal -> Bat Classes in order.\n");

            Console.WriteLine(
                "Batman inherets all of the properties and methods accociated with those Classes.\n" +
                "He also inherets the ICanFly Interface from the Bat Class.\n");

            Batman bruceWayne = new Batman();

            Console.WriteLine($"How Batman eats: {bruceWayne.Eat(bruceWayne.Diet)}\n");

            Console.WriteLine($"What does Batman wear: {bruceWayne.BodyCovering}\n");

            Console.WriteLine($"What sound does Batman make: {bruceWayne.MakeSound(bruceWayne.Sound)}\n");

            Console.WriteLine(
                $"Is it true that Batman has inner ear bones: {bruceWayne.HasEarBones}\n");

            Console.WriteLine($"How does Batman fly: {bruceWayne.HowIFly()}\n");
        }
Exemplo n.º 2
0
    static void Main()
    {
        Animal[] animals = new Animal[4];

        Animal animal = new Animal();
        Bird   bird   = new Bird();

        bird.name = "Vasia";
        Cat  cat  = new Cat();
        Lion lion = new Lion();

        animals [0] = animal;
        animals [1] = bird;
        animals [2] = cat;
        animals [3] = lion;

        animal.Eat();
        bird.Eat();
        cat.Eat();
        lion.Eat();

        //animal.cells = 0;

        Console.WriteLine();

        int i;

        for (i = 0; i < 4; i++)
        {
            animals[i].Eat();
        }

        Console.WriteLine();

        ((Cat)animals[2]).Eat();

        Console.WriteLine();

        IFlying[] flying = new IFlying[2];

        Bat bat = new Bat();

        flying [0] = bat;
        flying [1] = bird;

        for (i = 0; i < 2; i++)
        {
            flying [i].Fly();
        }

        Console.WriteLine();

        Man    man    = new Man();
        Batman batman = new Batman();

        man.Eat();
        batman.Eat();
        batman.Fly();

        Console.WriteLine();

        Console.WriteLine(Animal.Quantity);
    }