コード例 #1
0
    public static void Main()
    {
        Turtle turtle = new Turtle();

        Console.WriteLine(turtle);
        Console.WriteLine("The {0} can go {1} km/h ", turtle.GetName(), turtle.Speed);

        Console.WriteLine();

        Cheetah cheetah = new Cheetah();

        Console.WriteLine(cheetah);
        Console.WriteLine("The {0} can go {1} km/h ", cheetah.GetName(), cheetah.Speed);

        Console.WriteLine();

        Tomcat tomcat = new Tomcat();

        Console.WriteLine(tomcat);
        Console.WriteLine("The {0} can go {1} km/h ", tomcat.GetName(), tomcat.Speed);
        tomcat.SayMyaau();

        Console.WriteLine();

        Kitten kitten = new Kitten();

        Console.WriteLine(kitten);
        Console.WriteLine("The {0} can go {1} km/h ", kitten.GetName(), kitten.Speed);
        kitten.Breed = "siamska";//Ot dopalnitelnoto Property ot Cat
        Console.WriteLine("The breed of the {0} is {1}", kitten.GetName(), kitten.Breed);
        kitten.SayMyaau();

        // This will not compile (Cat is abstract -> cannot be instantiated)
        //Cat cat = new Cat();
    }
コード例 #2
0
    public static void Main()
    {
        Turtle turtle = new Turtle();
        Console.WriteLine(turtle);
        Console.WriteLine("The {0} can go {1} km/h ", turtle.GetName(), turtle.Speed);

        Console.WriteLine();

        Cheetah cheetah = new Cheetah();
        Console.WriteLine(cheetah);
        Console.WriteLine("The {0} can go {1} km/h ", cheetah.GetName(), cheetah.Speed);

        Console.WriteLine();

        Tomcat tomcat = new Tomcat();
        Console.WriteLine(tomcat);
        Console.WriteLine("The {0} can go {1} km/h ", tomcat.GetName(), tomcat.Speed);
        tomcat.SayMyaau();

        Console.WriteLine();

        Kitten kitten = new Kitten();
        Console.WriteLine(kitten);
        Console.WriteLine("The {0} can go {1} km/h ", kitten.GetName(), kitten.Speed);
        kitten.SayMyaau();

        // This will not compile (Cat is abstract -> cannot be instantiated)
        //Cat cat = new Cat();
    }
コード例 #3
0
    static void Main()
    {
        Turtle turtle = new Turtle();

        Console.WriteLine(turtle);
        Console.WriteLine("The {0} can go {1} km/h ", turtle.GetName(), turtle.Speed);

        Console.WriteLine();

        Cheetah cheetah = new Cheetah();

        Console.WriteLine(cheetah);
        Console.WriteLine("The {0} can go {1} km/h ", cheetah.GetName(), cheetah.Speed);

        Console.WriteLine();

        Tomcat tomcat = new Tomcat();

        Console.WriteLine(tomcat);
        Console.WriteLine("The {0} can go {1} km/h ", tomcat.GetName(), tomcat.Speed);
        tomcat.SayMyaau();

        Console.WriteLine();

        Kitten kitten = new Kitten();

        Console.WriteLine(kitten);
        Console.WriteLine("The {0} can go {1} km/h ", kitten.GetName(), kitten.Speed);
        kitten.SayMyaau();

        // This wil not compile (Cat is abstract -> cannot be instantiated)
        //Cat cat = new Cat();
    }
コード例 #4
0
        static void Main(string[] args)
        {
            Dog firstDog = new Dog(2, "Sharo");
            Dog secondDog = new Dog(6, "Djaro");
            Dog thirdDog = new Dog(1, "Tobi");
            Dog fourthDog = new Dog(5, "Roni");

            Dog[] dogs = new Dog[]
            {
                firstDog, secondDog, thirdDog, fourthDog
            };

            Console.WriteLine("The average age of the dogs is: {0}", Animal.GetAverageAge(dogs));
            firstDog.MakeSound();
            Console.WriteLine();

            Cat firstCat = new Kitten(1, "Kitty");
            Cat secondCat = new Tomcat(2, "Bojko");
            Cat thirdCat = new Cat(4, "Myrzel", "male");

            Cat[] cats = new Cat[] 
            {
                firstCat,
                secondCat,
                thirdCat
            };

            Console.WriteLine("The average age of the cats is: {0}", Animal.GetAverageAge(cats));
            Console.WriteLine();
            
            Console.WriteLine("The kitten's name is: {0} ", firstCat.GetName());
            Console.WriteLine("The kitten's age is: {0}", firstCat.GetAge());
            Console.WriteLine("All kittens are {0}", firstCat.Sex);
            firstCat.MakeSound();
            Console.WriteLine();

            Console.WriteLine("The tomcat's name is: {0}", secondCat.GetName());
            Console.WriteLine("All tomcats are {0}", secondCat.Sex);
            secondCat.MakeSound();

            thirdCat.MakeSound();
            Console.WriteLine();

            Frog froggy = new Frog(22, "Prince");
            froggy.MakeSound();

        }
コード例 #5
0
    static void Main()
    {
        Turtle turtle = new Turtle();

        Console.WriteLine(turtle);                         //I am turtle
        Console.WriteLine("The {0} can go {1} km/h ",
                          turtle.GetName(), turtle.Speed); //The turtle can go 1 km/h

        Console.WriteLine();

        Cheetah cheetah = new Cheetah();

        Console.WriteLine(cheetah);                          //I am cheetah
        Console.WriteLine("The {0} can go {1} km/h ",
                          cheetah.GetName(), cheetah.Speed); //The cheetah can go 100 km/h

        Console.WriteLine();

        Tomcat tomcat = new Tomcat();

        Console.WriteLine(tomcat);                         //I am tomcat
        Console.WriteLine("The {0} can go {1} km/h ",
                          tomcat.GetName(), tomcat.Speed); //The tomcat can go 20 km/h
        tomcat.SayMyaau();                                 //Tomcat muaaaaaaaau

        Console.WriteLine();

        Kitten kitten = new Kitten();

        Console.WriteLine(kitten);                         //I am kitten
        Console.WriteLine("The {0} can go {1} km/h ",
                          kitten.GetName(), kitten.Speed); //The kitten can go 5 km/h
        kitten.SayMyaau();                                 //Kitten miau, miaau

        // This wil not compile (Cat is abstract -> cannot be instantiated)
        //Cat cat = new Cat();
    }