C# Interface inheritance

Interfaces Inheriting Interfaces

One interface can inherit another. The syntax is the same as for inheriting classes.


using System;/*from www  . ja  v  a2s.  c  o m*/
interface Printable{
   void print();
}

interface Displayable:Printable{
   void output();
}

class MyClass : Displayable{
   public void print(){
     Console.WriteLine("print");
   }
   public void output(){
     Console.WriteLine("output");
   
   }
}

class Test
{
    static void Main()
    {

        Displayable cls = new MyClass();

        cls.print();
        cls.output();

    }
}

The output:

Next chapter...

What you will learn in the next chapter:

  1. How to add indexer to an interface
Home »
  C# Tutorial »
    C# Types »
      C# Interface
C# Interfaces
C# interface implementation
C# Explicit interface
C# Interface inheritance
C# Indexer in an interface
C# Interface Properties
C# struct and interface
C# virtual interface