实现接口的类是否继承接口实现的问题

在类A中实现了某些接口,以后在继承类A时也会一起继承所有接口的实现,而不需要在继承类中显式地进行接口的实现。除非在继承类中想要改变父类的接口实现。具体的代码如下所示:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace ConsoleApplication1

{

    interface ITest

    {

        void TestMethod1();

    }

 

    public class TestClass1 : ITest

    {

        public void TestMethod1()

        {

            Console.WriteLine("TestClass1 TestMethod1");

        }

    }

 

    public class TestInheritClass1 : TestClass1

    {

       

    }

 

    public class TestInheritClass2 : TestClass1, ITest

    {

        public void TestMethod1()

        {

            Console.WriteLine("TestInheritClass2 TestMethod1");

        }

    }

 

    class Program

    {

        static void Main(string[] args)

        {

            ITest testInterface = new TestClass1();

            ITest testInheritInterface1 = new TestInheritClass1();

            ITest testInheritInterface2 = new TestInheritClass2();

 

            testInterface.TestMethod1();

            testInheritInterface1.TestMethod1();

            testInheritInterface2.TestMethod1();

            Console.ReadLine();

        }

    }

}

程序执行的结果如下图所示:

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值