in Education by
What happens if the inherited interfaces have conflicting method names?

1 Answer

0 votes
by
edited by

If we implement multiple interfaces in the same class with conflict method names, we don’t need to define all. In other words, we can say if we have conflict methods in the same class, we can’t implement their body independently in the same class because of the same name and same signature. Therefore, we have to use the interface name before the method name to remove this method confiscation. Let’s see an example:

  1. interface testInterface1 {  
  2.     void Show();  
  3. }  
  4. interface testInterface2 {  
  5.     void Show();  
  6. }  
  7. class Abc: testInterface1,  
  8.     testInterface2 {  
  9.         void testInterface1.Show() {  
  10.             Console.WriteLine("For testInterface1 !!");  
  11.         }  
  12.         void testInterface2.Show() {  
  13.             Console.WriteLine("For testInterface2 !!");  
  14.         }  
  15.     }  

Now see how to use these in a class:

  1. class Program {  
  2.     static void Main(string[] args) {  
  3.         testInterface1 obj1 = new Abc();  
  4.         testInterface1 obj2 = new Abc();  
  5.         obj1.Show();  
  6.         obj2.Show();  
  7.         Console.ReadLine();  
  8.     }  
  9. }  

Output

ASP.NET

Related questions

0 votes
    What happens when we access the same variable defined in two interfaces implemented by the same class? (a) ... Packages of Java Select the correct answer from above options...
asked Feb 23, 2022 in Education by JackTerrance
0 votes
    In a certain city, 5% of all the persons in town have unlisted phone numbers. If you select 100 names at ... directory, how many people selected will have unlisted phone numbers?...
asked Feb 12, 2021 in Education by JackTerrance
0 votes
    What is Boxing and Unboxing in C#?...
asked Jul 9, 2021 in General by JackTerrance
0 votes
    What is the Tab Control in WPF?...
asked Apr 9, 2021 in Education by JackTerrance
0 votes
0 votes
0 votes
    How can we create Borderless Window in WPF?...
asked Apr 9, 2021 in Education by JackTerrance
...