Skip to content

Instantly share code, notes, and snippets.

@VikashChauhan51
Created June 20, 2022 05:23
Hierarchical Inheritance implementation in C#
namespace Inheritance;
public class Vehicle
{
public bool CanRun { get; set; }
}
public class Car: Vehicle
{
public string Model { get; set; }
public bool HasEngine { get; set; }
public int Wheels { get; set; }
public void VehicleType()
{
Console.WriteLine("Car");
}
}
public class Bike : Vehicle
{
public string Model { get; set; }
public bool HasEngine { get; set; }
public int Wheels { get; set; }
public void VehicleType()
{
Console.WriteLine("Bike");
}
}
public class Program
{
public static void Main(string[] args)
{
var myCar = new Car()
{
Model = "Maruti 800",
CanRun = true, // Inherited from Vehicle base class.
HasEngine = true,
Wheels = 4
};
var myBike = new Bike()
{
Model = "Yamaha rx100",
CanRun = true, // Inherited from Vehicle base class.
HasEngine = true,
Wheels = 2
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment