Multiple Inheritance In C# Using Interfaces

This is the simple mathematical operation program demonstrating how multiple inheritance can be achieved in C# using Interface Concept.

Multiple Inheritance in C#

 
Multiple Inheritance can be achieved in C# using Interfaces.

This is the simple mathematical operation program demonstrating how multiple inheritance can be achieved in C# using Interface Concept.

  1. using System;    
  2. using System.Collections.Generic;    
  3. using System.Linq;    
  4. using System.Text;    
  5.      
  6. namespace MultipleInheritApplication    
  7. {    
  8.     interface calc1    
  9.     {    
  10.         int add(int a, int b);    
  11.     }    
  12.     interface calc2    
  13.     {    
  14.         int sub(int x, int y);    
  15.     }    
  16.     interface calc3    
  17.     {    
  18.         int mul(int r, int s);    
  19.     }    
  20.     interface calc4    
  21.     {    
  22.         int div(int c, int d);    
  23.     }    
  24.     class Calculation : calc1, calc2, calc3, calc4    
  25.     {    
  26.         public int result1;    
  27.         public int add(int a, int b)    
  28.         {    
  29.             return result1 = a + b;    
  30.         }    
  31.         public int result2;    
  32.         public int sub(int x, int y)    
  33.         {    
  34.             return result2 = x - y;    
  35.         }    
  36.         public int result3;    
  37.         public int mul(int r, int s)    
  38.         {    
  39.             return result3 = r * s;    
  40.         }    
  41.         public int result4;    
  42.         public int div(int c, int d)    
  43.         {    
  44.             return result4 = c / d;    
  45.         }    
  46.      
  47.         class Program    
  48.         {    
  49.             static void Main(string[] args)    
  50.             {    
  51.                 Calculation c = new Calculation();    
  52.                 c.add(8, 2);    
  53.                 c.sub(20, 10);    
  54.                 c.mul(5, 2);    
  55.                 c.div(20, 10);    
  56.                 Console.WriteLine("Multiple Inheritance concept Using Interfaces :\n ");    
  57.                 Console.WriteLine("Addition: " + c.result1);    
  58.                 Console.WriteLine("Substraction: " + c.result2);    
  59.                 Console.WriteLine("Multiplication :" + c.result3);    
  60.                 Console.WriteLine("Division: " + c.result4);    
  61.                 Console.ReadKey();    
  62.             }    
  63.         }    
  64.     }    

Output
 
multiple inheritance in C# 
 
Further recommended readings on C# inheritance 
 
Here are more articles on inheritance and object oriented programming in C#.
 
Types of Inheritance in C# 
In this article, we will learn about C# inheritance and types of inheritance in C# and .NET with code examples.

Overview of Inheritance in C#
In this article, you will learn about inheritance in C#. Inheritance is one of the major pillars of object-oriented programming. Here is an overview of inheritance.

Inheritance with Example in C#
Here are some example of inheritance using C#.
 
Learn all about Inheritance in C#
In this article, you will learn about Inheritance in C#.
 
Playing with inheritance in C#
This article explains the various behaviors of inheritance in various cases.
 
Inheritance examples in C#
This article explains inheritance with examples in C#.
 
Multiple Inheritance in C#
Can you inherit from multiple classes in C#? Simply put, this cannot be done. However there are ways around it. From a design perspective you must ask yourself, will a Class fully represent an object?
 
Multiple Inheritance in C# using Interfaces
This is the simple mathematical operation program demonstrating how multiple inheritance can be achieved in C# using Interface Concept.
 
Inheritance in C#
Interface inheritance defines a new interface in terms of one or more existing interfaces. Implementation inheritance defines a new implementation in terms of one or more existing implementations.