Esempio n. 1
0
        static void Main(string[] args)
        {
            IAnimal iAnimalobj = new Animal();
            IAnimal iMammalobj = new Mammal();
            IAnimal iPetobj    = new Pet();
            IAnimal iHumanobj  = new Human();
            IAnimal iCatobj    = new Cat();
            IAnimal iDogobj    = new Dog();
            IAnimal iBirdobj   = new Birds();
            IAnimal iEagleobj  = new Eagle();

            Mammal mHumanobj = new Human();
            Mammal mPetobj   = new Pet();
            Mammal hCatobj   = new Cat();
            Mammal hDogobj   = new Dog();

            Human humanobj = new Human();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Animal dolphin = new Dolphin();

            dolphin.Age = 6;
            dolphin.Eat();
            dolphin.Sleep();
            ((Dolphin)dolphin).Swim();
            Console.WriteLine(dolphin.Age + " years old");
            Console.WriteLine(dolphin.GetType());

            Animal lion = new Lion();

            lion.Age = 3;
            lion.Eat();
            lion.Sleep();
            ((Lion)lion).Attack();
            ((Lion)lion).Roar();
            Console.WriteLine(lion.Age + " years old");

            Animal eagle = new Eagle();

            eagle.Age = 4;
            eagle.Eat();
            eagle.Sleep();
            ((Eagle)eagle).Attack();
            ((Eagle)eagle).Fly();
            Console.WriteLine(eagle.Age + " years old");

            Animal bee = new Bee();

            bee.Age = 2;
            ((Bee)bee).Fly();
            bee.Eat();
            bee.Sleep();
            Console.WriteLine(bee.Age + " years old");
        }