C# | Multiple Inheritance with Interface Example

In this tutorial i am going to explain how to use multiple inheritance in c# with using interface. or how to implement multiple inheritance in c#. or using interface to implement multiple inheritances in c# or vb.net. In c# and Vb.Net multiple inheritance can be implement by using interfaces.

In C# or Vb.Net Multilevel inheritance is possible to implement but for multiple inheritance we need to use interface. By using interface we can implement Multiple inheritance.

So, Let's Take one Example of Interface for  implement Multiple Inheritance in C# and Vb.Net.
using System;
using System.Data;
 
namespace inheritance_example
{
    class DemoProgram
    {
        static void Main(string[] args)
        {
            Operations obj = new Operations();
            Console.WriteLine("This is Example of Multiple inheritance using interface \n ");
            Console.WriteLine("Result Number 1: " + obj.method1(20, 50));
            Console.WriteLine("Result Number 2: " + obj.method2(100, 40));
            Console.WriteLine("Result Number 3: " + obj.method3(30, 4));
            Console.ReadLine();
        }
    }
    class Operations : inface1, inface2, inface3
    {
        public int method1(int g, int h)
        {
            return g + h;
        }
        public int method2(int i, int j)
        {
            return i - j;
        }
        public int method3(int k, int l)
        {
            return k * l;
        }
    }
    interface inface1
    {
        int method1(int a, int b);
    }
    interface inface2
    {
        int method2(int c, int d);
    }
    interface inface3
    {
        int method3(int e, int f);
    }
}
Output:

Example of Multiple Inheritance

Previous
Next Post »

If you have any kind of question about any post, Feel free to ask.You can simply drop a comment below post. Your feedback and suggestions will be highly appreciated. ConversionConversion EmoticonEmoticon