Q:

What happens if the inherited interfaces have conflicting method names?

0

What happens if the inherited interfaces have conflicting method names?

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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:

interface testInterface1
{
    void Show();
}
interface testInterface2
{
    void Show();
}
class Abc: testInterface1,
    testInterface2
{
    void testInterface1.Show()
    {
        Console.WriteLine("For testInterface1 !!");
    }
    void testInterface2.Show()
    {
        Console.WriteLine("For testInterface2 !!");
    }
}

Now see how to use these in a class:

class Program
{
    static void Main(string[] args)
    {
        testInterface1 obj1 = new Abc();
        testInterface1 obj2 = new Abc();
        obj1.Show();
        obj2.Show();
        Console.ReadLine();
    }
}

Output:

For testInterface1 !!
For testInterface1 !!

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C# Interview Questions and Answers,You Need To Know

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
What is Constructor in C#?... >>
<< What is the advantage of abstract class?...