static void doWork() { Console.WriteLine("Journey by airplane:"); Airplane myPlane = new Airplane(); //making airplane class into myplane to call myPlane.StartEngine("Contact"); myPlane.TakeOff(); myPlane.Drive(); myPlane.Land(); myPlane.StopEngine("Whirr"); Console.WriteLine(); Console.WriteLine("Journey by car:"); Car myCar = new Car(); //making car class into mycar to call myCar.StartEngine("Brm brm"); myCar.Accelerate(); myCar.Drive(); myCar.Brake(); myCar.StopEngine("Phut phut"); Console.WriteLine(); Console.WriteLine("Journey by motorcycle"); Motorcycle R6 = new Motorcycle(); R6.StartEngine(" RROOOM ROOOOM"); R6.GOFAST(); R6.Drive(); R6.SKID(); R6.StopEngine("CLANK CLUNK CLANK"); Console.WriteLine(); Console.WriteLine("Journey by Cigarette Boat"); Boat Cigarette = new Boat(); Cigarette.StartEngine(" CHUG CHUG"); Cigarette.Swoosh(); Cigarette.Drive(); Cigarette.Whip(); Cigarette.StopEngine("It doesnt matter - tony"); Console.WriteLine(); Console.WriteLine("Journey by Vehicle"); Vehicle V = new Vehicle(); V.StartEngine("Start Engine"); V.Drive(); //virtual method, desginged to be overriden V.StopEngine("Stop ENgine"); }
static void doWork() { Console.WriteLine("Test vehicle"); Vehicle v = new Vehicle(); v.StartEngine("RUM RUM"); v.Drive(); v.StopEngine("GIN GIN"); Console.WriteLine("------------------------------------"); Console.WriteLine("Journey by airplane:"); Airplane myPlane = new Airplane(); myPlane.StartEngine("Contact"); myPlane.TakeOff(); myPlane.Drive(); // prints "Flying" from Car class from overloaded method in Derived class Airplane. myPlane.Land(); myPlane.StopEngine("Whirr"); Console.WriteLine("------------------------------------"); Console.WriteLine("Journey by car:"); Car Car1 = new Car(); Car1.StartEngine("Brm brm"); Car1.Accelerate(); Car1.Drive(); // prints Motoring" Car1.Brake(); Car1.StopEngine("Phut phut"); Console.WriteLine("-------------------------------------"); Console.WriteLine("\nTesting polymorphism"); Vehicle w = new Vehicle(); w.Drive(); w = Car1; w.Drive(); w = myPlane; w.Drive(); Console.WriteLine("-------------------------------------"); Console.WriteLine("Journey by motorcycle"); Motorcycle mc = new Motorcycle(); mc.StartEngine("Voom Voom"); mc.Accelerate(); mc.Drive(); mc.Brake(); mc.StopEngine("Klunk Klunk"); }