Ejemplo n.º 1
0
        static void testPolymorphism()
        {
            Animal animal  = new Animal(4);
            Animal tigre   = new Tigre(5);
            Animal taureau = new Taureau(6);

            animal.seDeplacer();
            tigre.seDeplacer();
            taureau.seDeplacer();
        }
Ejemplo n.º 2
0
        static void testCating()
        {
            int nb = 3;

            double nbd = nb;

            Console.WriteLine("Entier : " + nb);
            Console.WriteLine("Double : " + nbd);
            Console.WriteLine("");
            double nbd2 = 4.002;

            nb = (int)nbd2;
            Console.WriteLine("Double : " + nbd2);
            Console.WriteLine("Entier : " + nb);
            Console.WriteLine("");
            int    nb2  = 4;
            double nb2d = Convert.ToDouble(5.1);
            int    nb21 = Convert.ToInt32(nb2d);

            Console.WriteLine("");

            Animal  animal  = new Animal(5);
            Tigre   tigre   = new Tigre(4);
            Taureau taureau = new Taureau(6);

            Console.WriteLine("Animal : " + animal.getAge());
            Console.WriteLine("Tigre : " + tigre.getAge());
            Console.WriteLine("Taureau: " + taureau.getAge());
            Console.WriteLine("");

            animal = tigre;
            Console.WriteLine("Animal : " + animal.getAge());

            tigre = (Tigre)animal;
            Console.WriteLine("Tigre : " + tigre.getAge());
        }