コード例 #1
0
        //static void Main(string[] args)
        //{
        //    // Declare objects of the derived classes and test which version
        //    // of ShowDetails is run, base or derived.
        //    TestCars1();

        //    // Declare objects of the base class, instantiated with the
        //    // derived classes, and repeat the tests.
        //    TestCars2();

        //    // Declare objects of the derived classes and call ShowDetails
        //    // directly.
        //    TestCars3();

        //    // Declare objects of the base class, instantiated with the
        //    // derived classes, and repeat the tests.
        //    TestCars4();
        //}

        public static void TestCars1()
        {
            System.Console.WriteLine("\nTestCars1");
            System.Console.WriteLine("----------");

            Car car1 = new Car();

            car1.DescribeCar();
            System.Console.WriteLine("----------");

            // Notice the output from this test case. The new modifier is
            // used in the definition of ShowDetails in the ConvertibleCar
            // class.
            ConvertibleCar car2 = new ConvertibleCar();

            car2.DescribeCar();
            System.Console.WriteLine("----------");

            Minivan car3 = new Minivan();

            car3.DescribeCar();
            System.Console.WriteLine("----------");
        }