Multiple Interface With Same Defination Name

Two different interface have same method name and only return type is different from one and otther

Consider a class derives both interfaces and want to call interface specific method

we start with simple example

First Step: A two interfaces with same method name and different return type

///// DEFINE INTERFACES /////
   interface One
   {
     int get();
   }
   interface Two
   {
     void get();
   }

Second Step: Implement Both Interfaces

 class Common : One,Two
   {
     int a = 10;
     public void get()
     {
         a = 12;
     }
     int One.get()
     {
         return a;
     }
   }

Third Step: Call Interface Specific Function

class Program
   {
     static void testing1(dynamic one)
     {
         Console.WriteLine(one);
     }
     static void Main(string[] args)
     {
         Common OBJ = new Common();
         OBJ.get();
         Console.WriteLine(((One)OBJ).get()); 
      }
   }
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s