The derived class inherits the member of the base class is called inheritance. This is one object that has all the properties and behaviors of its parent object. Using inheritance we can reuse the code. We can achieve a single level and multi-level inheritance.
public class Employee {
public float salary = 400;
}
public class Programmer: Employee
{
public float bonus = 100;
}
class TestInheritance{
public static void Main(string[] args)
{
Programmer p1 = new Programmer();
Console.WriteLine("Salary: " + p1.salary);
Console.WriteLine("Bonus: " + p1.bonus);
}
}
Inheritance is a mechanismin which one object acquires all the properties and behaviour of another object of another class. It represents IS-A relationship. It is used for Code Resusability and Method Overriding.
Liked By
Write Answer
What is Inheritance?
Join MindStick Community
You have need login or register for voting of answers or question.
Shrikant Mishra
05-Oct-2019The derived class inherits the member of the base class is called inheritance. This is one object that has all the properties and behaviors of its parent object. Using inheritance we can reuse the code. We can achieve a single level and multi-level inheritance.
Anonymous User
23-Feb-2015