Created
June 20, 2022 05:23
Hierarchical Inheritance implementation in C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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