Java, .NET, PHP, PYTHON, ANGULAR, .NET, ML, Data Scince, Testing, CI Tutorials in Easy Languages.

"Best Software Training, Internship, Project Development center of Indore India, Helpline 780506-3968"

Inheritance in C#:- 



It means Reusability, using this we can acquire the features of the parent class to the child class. Inheritance provides a relationship between classes.

Type of Inheritance:-


1.1 using Class

1)  Single  Inheritance:-   We can adopt the features of base class to derived class

  class A
    {
       internal  void fun1()
        {
            Console.WriteLine("A");
        }
    }
    class B:A
    {
       internal  void fun2()
        {
            Console.WriteLine("B");
        }
     
    }


2) Multilevel Inheritance:-  We can adopt the features of base class to a derived class to sub derived class

class A
    {
       internal  void fun1()
        {
            Console.WriteLine("A");
        }
    }
    class B:A
    {
       internal  void fun2()
        {
            Console.WriteLine("B");
        }
     
    }

    class C : B
    {
        internal void fun3()
        {
            Console.WriteLine("C");
        }

        static void Main()
        {
            C obj = new C();
            obj.fun1();
            obj.fun2();
            obj.fun3();
            Console.ReadKey();
        }
    }


3) Hierarchical:-  One base class features will be implemented into multiple child class similar to tree structure.

class A
    {
       internal  void fun1()
        {
            Console.WriteLine("A");
        }
    }
    class B:A
    {
       internal  void fun2()
        {
            Console.WriteLine("B");
        }
     
    }

    class C : A
    {
        internal void fun3()
        {
            Console.WriteLine("C");
        }

        static void Main()
        {
            C obj = new C();
            obj.fun1();
            obj.fun3();
            B obj1 = new B();
            obj1.fun1();
            obj1.fun2();
            Console.ReadKey();
        }
    }

1.2 using Interface:- 

 these features will be implemented into the interface concept 

1)  Single

2) Multiple





Post a Comment

If you have any doubt in programming or join online classes then you can contact us by comment .

Previous Post Next Post