Sobes.tech
Junior — Middle

How is interface inheritance implemented in object-oriented programming?

sobes.tech AI

Answer from AI

In C#, interface inheritance is implemented using the : keyword when declaring an interface. One interface can inherit from one or more other interfaces, combining their contracts.

This allows creating more complex interfaces based on basic ones, ensuring reusability and extensibility.

Example:

public interface IReadable
{
    void Read();
}

public interface IWritable
{
    void Write();
}

// Interface inheriting from two others
public interface IReadWrite : IReadable, IWritable
{
    void Close();
}

A class implementing IReadWrite must implement all methods from IReadable, IWritable, and IReadWrite.