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.
Join MindStick Community
You need to log in or register to vote on answers or questions.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
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.