接口的多继承和显示实现

View Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 接口的多继承
{
    class Program
    {
        static void Main(string[] args)
        {
            IA a = new C();
            a.Breath();
            IB b = new C();
            b.Breath();

        }
    }
    class C : IA, IB
    {
       
        void IA.Breath()
    {
        Console.WriteLine("A");
    }
        void IB.Breath()
     {
         Console.WriteLine("B");
     }
    }
}

类和类之间是单继承的,一个类只能继承一个基类,

类与接口之间是多继承的。一个类可以实现多个接口

如果一个类继承了多个接口,就必须实现接口的所有成员,如果有些接口有重名的成员,就需要显示的实现。即在方法前加上接口的名称

posted on 2013-05-08 22:25  杨柳清枫2012  阅读(118)  评论(0)    收藏  举报

导航