What is Inheritance.


=> Inheritance is reusability of the code.

=> Inheritance is a mechanism of acquiring the features and behaviours of a class by another class. The class whose members are inherited is called the base class, and the class that inherits those members is called the derived class.



Example :-

using System;

namespace Inheritance
{
    class Program
    {
        static void Main(string[] args)
        {
            child child = new child();
            child.print();
            Console.ReadLine();
        }
    }
    class Parrent
    {
        public Parrent()
        {
            Console.WriteLine("Parrent constrocter calling");
        }

        public void print()
        {
            Console.WriteLine("I am parrent class");
        }
    }

    class child:Parrent
    {

        public child()
        {
            Console.WriteLine("Child constrocter");
        }


    }

}
OUTPUT

Parrent constrocter calling
I am parrent class
Child constrocter

Share

& Comment

0 comments:

Post a Comment

 

Copyright © 2019 HART™ is a registered trademark.