VOOZH about

URL: https://www.geeksforgeeks.org/c-sharp/c-sharp-multiple-inheritance-using-interfaces/

⇱ C# | Multiple inheritance using interfaces - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

C# | Multiple inheritance using interfaces

Last Updated : 3 Feb, 2026

Multiple inheritance means a class can inherit features from more than one base class. While this is supported in some languages, C# does not allow multiple inheritance with classes to avoid ambiguity and complexity (such as the diamond problem).

However, C# supports multiple inheritance through interfaces. A class can implement multiple interfaces and thereby acquire behavior from multiple sources.

👁 multiple-inheritance
Illustration of Multiple Inheritance

Interface in C#

An interface is a contract that defines:

  • Method signatures
  • Properties
  • Events
  • Indexers

A class that implements an interface must provide implementations for all its members. A class can implement multiple interfaces, which enables multiple inheritance-like behavior.

Implementing Multiple Inheritance Using Interfaces

A class implements interfaces by listing them after the class name, separated by commas. The class must then provide implementations for all interface members.

Syntax:

class ClassName : IInterface1, IInterface2
{
// implement all interface methods here
}

This allows a single class to support multiple behaviors defined by different interfaces.

Example: In this example, a class implements two interfaces and provides implementations for both.


Output
Area: 50
Color: Blue

Explanation:

  • IShape and IColor are two separate interfaces defining different behaviors.
  • Each interface declares one method without implementation.
  • Rectangle implements both interfaces using : IShape, IColor.
  • The class must provide implementations for both GetArea() and GetColor().
  • Constructor initializes the rectangle’s dimensions and color.
  • In Main(), the object calls both interface methods normally.

Implementing Multiple Interfaces with Delegation

A class implementing multiple interfaces does not need to implement all logic directly. It can delegate the implementation to helper classes while still fulfilling the interface contracts.


Output
Languages:
C
C++
C#
Java

Courses:
System Design
Python
DSA
Java

Explanation:

  • Two interfaces define two independent capabilities: language listing and course listing.
  • LanguageService implements ILanguageProvider.
  • CourseService implements ICourseProvider.
  • Portal implements both interfaces.
  • Instead of writing logic again, Portal delegates calls to helper objects.
  • This pattern improves reuse and separation of concerns.
  • The caller only interacts with the Portal class while multiple behaviors are supported.

Key Rules for Multiple Inheritance via Interfaces

  • A class can implement multiple interfaces
  • Interfaces cannot contain instance fields
  • All interface members must be implemented
  • Interface methods are public by default
  • Multiple interfaces can define the same method name (explicit implementation may be required)
Comment

Explore