2009年12月23日水曜日

3つのInterfaceを多重継承してそのInterfaceを実装してみる。

using System;


interface Interface1
{
    void method1(int a);
}
interface Interface2
{
    void method2(int a,int b);
}
interface Interface3
{
    void method3(string s);
}
// インターフェイスの多重継承
interface Interface : Interface1,
    Interface2, Interface3
{
    void method();
}
// Interfaceの実装
class DerivedClass : Interface
{
    public void method1(int a)
    {
        Console.WriteLine(a);
    }
    public void method2(int a,int b)
    {
        Console.WriteLine(a+b);
    }
    public void method3(string s)
    {
        Console.WriteLine(s);
    }
    public void method()
    {
        Console.WriteLine("Method");
    }
}
class MainClass
{
    static void Main()
    {
        DerivedClass drv = new DerivedClass();
        // 出力値:1
        drv.method1(1);
        // 出力値:3
        drv.method2(1, 2);
        // 出力値:Method
        drv.method();
    }
}

0 コメント:

コメントを投稿