C# polymorphism
Last modified: July 01, 2021class Vehicle
{
public virtual void MyModel()
{
Console.WriteLine("I do not have it");
}
}
class Tesla: Vehicle
{
public override void MyModel()
{
Console.WriteLine("I am a Tesla Model 3 Car");
}
}
class BMW : Vehicle
{
public override void MyModel()
{
Console.WriteLine("I am a BMW i4 Car");
}
}
class Program
{
static void Main(string[] args)
{
var vechile = new Vehicle();
var tesla = new Tesla();
var bmw = new BMW();
vechile.MyModel();
tesla.MyModel();
bmw.MyModel();
}
}