Information Technology Reference
In-Depth Information
An Inherited Member As an Implementation
A class implementing an interface can inherit the code for an implementation from one of its
base classes. For example, the following code illustrates a class inheriting implementation
code from a base class.
￿ IIfc1 is an interface with a method member called PrintOut .
￿ MyBaseClass contains a method called PrintOut that matches IIfc1 's method.
￿Class Derived has an empty declaration body, but derives from class MyBaseClass and
contains IIfc1 in its base class list.
￿
Even though Derived 's declaration body is empty, the code in the base class satisfies the
requirement to implement the interface.
interface IIfc1 { void PrintOut(string s); }
class MyBaseClass // Declare base class
{
public void PrintOut(string s) // Declare the method.
{
Console.WriteLine("Calling through: {0}", s);
}
}
class Derived : MyBaseClass, IIfc1 // Declare class
{
}
Search WWH ::




Custom Search