What is Inheritance?

Total Post:23

Points:115

 963  View(s)
Ratings:
Rate this:
  1. What is Inheritance?

    Inheritance is a mechanism in 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.

      Modified On Mar-27-2018 06:51:50 AM
  1. What is Inheritance?

    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);
    }
    }

Answer