Abstract Classes and Interfaces

Abstract classes can implement interfaces. Abstract classes must provide the implementation code of all methods declared in the interface. An abstract class can also map the interface methods to abstract methods within the class, as shown in the following example:

interface MyInterface 
{
    void Method1(); 
    void Method2(); 
    void Method3(); 
} 
abstract class MyClass: MyInterface 
{
    public abstract void Method1(); 
    public abstract void Method2(); 
    public abstract void Method3(); 
}

A mapping is created between the interface MyInterface and the abstract methods, Method1(), Method2(), and Method3(), in the MyClass class. However, these methods must be overridden in nonabstract classes derived from MyClass. As a result, the ...

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.