Interface Implementation Inheritance

A class inherits the interface mappings from the base class. A class cannot alter the interface mapping that it inherits from the base class without explicitly reimplementing an interface. Consider the following:

interface Inter1 
{
    void Method1(); 
} 
class MyClass: Inter1 
{
    public void Method1() 
    {
    } 
} 
class MySecondClass: MyClass 
    {
    new public void Method1() 
    {
    } 
}

In this example, the Method1() method in the MySecondClass class hides the method by the same name in the MyClass class. However, this does not alter the mapping of Inter1.Method1() to MyClass.Inter1(). Consider the following code snippet:

 MyClass mc = new MyClass(); MySecondClass ms = new MySecondClass(); Inter1 ic = mc; Inter1 it = ms; mc.Method1();// ...

Get Special Edition Using C# now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.