using System.Collections.Generic;
public string GetTypeName()
return String.Format("{0,12}", GetType().Name + ":");
public void DescribeCar()
Console.Write("{0} (Base) Four wheels and an engine. ", GetTypeName());
public virtual void ShowDetails(bool showClassName = true)
Console.Write("{0} ", GetTypeName());
Console.WriteLine("(Base) Standard transportation.");
public class Convertible : Car
public new void ShowDetails(bool showClassName = true)
Console.Write("{0} ", GetTypeName());
Console.WriteLine("(New) A roof that opens up.");
public class Minivan : Car
public override void ShowDetails(bool showClassName = true)
Console.Write("{0} ", GetTypeName());
Console.WriteLine("(Over) Carries seven people.");
public const string line = "----------";
public static void Main()
public static void TestCars1()
Console.WriteLine("\nTestCars1");
Convertible car2 = new Convertible();
Minivan car3 = new Minivan();
public static void TestCars2()
Console.WriteLine("\nTestCars2");
var cars = new List<Car> { new Car(), new Convertible(), new Minivan() };
foreach (var car in cars)
public static void TestCars3()
Console.WriteLine("\nTestCars3");
Convertible car2 = new Convertible();
Minivan car3 = new Minivan();
public static void TestCars4()
Console.WriteLine("\nTestCars4");
Car car2 = new Convertible();
Car car3 = new Minivan();