2010年1月4日月曜日

Interfaceを宣言して、Interfaceを実装したクラスを定義し、そしてそのクラスをインスタンス化して抽象メンバーである抽象メソッドにアクセスしてみる。
using System;


// Interfaceを宣言
interface IInterface
{
    // 抽象メンバー(抽象メソッド)
    void printOut();
}
// Interfaceの実装
class SampleClass : IInterface
{
    public void printOut()
    {
        Console.WriteLine
            ("SampleClass");
    }
}


class MainClass
{
    static void Main()
    {
        SampleClass sample = 
            new SampleClass();
        // 出力値:SampleClass
        sample.printOut();
    }
}

0 コメント:

コメントを投稿