Question: Complete the C# Implementation code of the following UML class diagram. Note that: The method drive in class Car will print out car drive The
Complete the C# Implementation code of the following UML class diagram.
Note that:
The method drive in class Car will print out car drive
The method drive in class Bus will print out bus drive
The method drive in class Truck will print out truck drive
In the Main method of class Program use a polymorphic reference to call drive() method, so you need to do the following
Create an array of 3 vehicles
Make the elements of the array point to Car, Bus and Truck objects
Use for loop to call drive() method on each object
using System;
namespace Final
{
class Program
{
static void Main(string[] args)
{
Answer //code to create the array
Answer //code to initialize the first element of the array with a car object
Answer //code to initialize the second element of the array with a buss object
Answer //code to initialize the third element of the array with a truck object
Answer // for loop header
{
Answer //calling drive on each object
}
}
}
public Answer Vehicle //Vehicle header
{
Answer // code for drive method
}
public class Car Answer // car header
{
public Answer // drive method header
{
Answer // drive method body
}
}
public class Bus Answer // Bus header
{
public Answer // drive method header
{
Answer // drive method body
}
}
public class TruckAnswer // Truck header
{
public Answer // drive method header
{
Answer // drive method body
}
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
