public void AddEngine(mycar car) { if (car is toyota) { toyota toyotaCar = (toyota)car; toyotaCar.Engine = "Дизельний двигун"; Console.WriteLine("Diesel додав двигун до авто : " + car); } }
static void Main_2(string[] args) { mycar toyotaCar1 = new toyota(); toyotaCar1.ManufactureCar(); Console.WriteLine(toyotaCar1 + "\n"); Diesel carWithDieselEngine = new Diesel(toyotaCar1); carWithDieselEngine.ManufactureCar(); Console.WriteLine(); mycar toyotaCar2 = new toyota(); Petrol carWithPetrolEngine = new Petrol(toyotaCar2); carWithPetrolEngine.ManufactureCar(); Console.ReadKey(); }