Click here to Skip to main content
16,021,464 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
public interface Iname
  {
      void display();
  }

  public interface Iname2
  {
      void display();
  }

  class Program
  {
       static void Main(string[] args)
      {
          cl obj = new cl();
          obj.display();
            Console.ReadLine();
      }
        }

  class cl : Iname, Iname2
  {
  public void display()
  {
      Console.WriteLine("speed is 300");
  }
  }

here my confusion is :just above which 'display'( Interface 1 or interface 2's) got implemented ans the ncalled..

i am confused..need help...?
Posted
Updated 4-Jul-11 7:22am
v2

The function that got implemented is actually the function defined in you class cl. The interface is only providing a template that the class my adhere to.

In this case as you are deriving from 2 interfaces that each have a function with the same signature and therefore fulfilling both interface definitions.
 
Share this answer
 
Comments
shikhar gilhotra 4-Jul-11 8:55am    
but what if i want to give a separate implementation top both the interface methods ??
Rhuros 4-Jul-11 9:05am    
http://msdn.microsoft.com/en-us/library/aa288461(v=vs.71).aspx example 2 in the article is a good starting point
The answer is: both. See here
Unless you implement then explicitely. See here

You can test with
public interface Iname
{
   void display();
}
 
public interface Iname2
{
   void display();
}
 
class Program
{
    static void Main(string[] args)
    {
	cl obj = new cl();
	Iname i1 = obj as Iname;
	i1.display();
	
	Iname2 i2 = obj as Iname2;
	i2.display();		
        System.Console.ReadLine();
    }
}
 
class cl : Iname, Iname2
{
    public void display()
    {
        System.Console.WriteLine("speed is 300");
    }
}
 
Share this answer
 
Comments
Uday P.Singh 4-Jul-11 14:26pm    
good answer my 5!
Sergey Alexandrovich Kryukov 4-Jul-11 16:22pm    
Good answer, my 5. Especially a link about explicit implementation. I would add: prefer explicit implementation. In particular, this is the only way to implement more than one indexed properties "this".
--SA
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900