C# – an example to illustrate Mutiple Inheritance through interfaces
A new year and a new post. Some of the readers might find me coding in C# and Python depending on my mood. Here is an example to show how to use interfaces in your C# program. This also shows multiple inheritance that can be achieved through interfaces.
using System;
interface GetSum
{
int GetSum();
}
interface CalcSum
{
void CalcSum(int x,int y);
}
namespace MultiInterface
{
class Addition : GetSum, CalcSum
{
int sum;
public int GetSum()
{
return sum;
}
public void CalcSum(int x, int y)
{
sum = x + y;
}
}
class Program
{
static void Main()
{
Addition objAdd = new Addition();
objAdd.CalcSum(8000,200);
Console.WriteLine("The Sum is = {0}", objAdd.GetSum());
}
}
}
OUTPUT:
nterface\MultiInterface\bin\Debug>MultiInterface.exe
The Sum is = 8200

Great article on C# inheritance. Another good article I have found is C# Inheritance and Polymorphism