实现接口的类是否继承接口实现的问题
2008-07-13 11:21
537 查看
在类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();
}
}
}
程序执行的结果如下图所示:
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();
}
}
}
程序执行的结果如下图所示:
相关文章推荐
- Anonymous Inner Class (匿名内部类) 是否可以extends(继承)其它类,是否可以implements(实现)interface(接口)?
- 第二,Anonymous Inner Class(匿名内部类) 是否可以extends(继承)其它类,是否可以implements(实现)interface(接口)?
- Anonymous Inner Class (匿名内部类)是否可以继承其他类,是否可以实现接口?
- 【Java面试题】13 Anonymous Inner Class (匿名内部类) 是否可以extends(继承)其它类,是否可以implements(实现)interface(接口)?
- Java - 接口是否可继承(extends)接口?抽象类是否可实现(implements)接口?抽象类是否可继承具体类(concrete class)?
- C#中如何判断实例是否继承了某个父类或者实现了某类接口
- as3 判断,某个类是否继承于某个类,某个类是否实现某个接口的方法
- 接口是否可继承接口? 抽象类是否可实现(implements)接口? 抽象类是否可继承实体类(concrete class)?
- 匿名内部类 是否可以继承其它类,是否可以实现接口
- 关于接口的实现和继承的问题
- 匿名内部类是否可以继承其它类是否可以实现接口 _JAVA面试题及答案
- 接口是否可继承接口? 抽象类是否可实现(implements)接口? 抽象类是否可继承实体类
- Java小程序---接口中抽象方法的实现(解决了JAVA语言不能多继承的问题)
- Anonymous Inner Class (匿名内部类) 是否可以extends(继承)其它类,是否可以implements(实现)interface(接口)?
- 接口是否可继承接口? 抽象类是否可实现(implements)接口? 抽象类是否可继承实体类(concrete class)?
- Java中类继承、接口实现的一些要注意的细节问题
- 接口是否可继承接口? 抽象类是否可实现(implements)接口? 抽象类是否可继承实体类(concrete class)?
- 如果类a继承类b,实现接口c,而类b和接口c中定义了同名变量,请问会出现什么问题?(瞬联)
- 接口是否可继承接口? 抽象类是否可实现(implements)接口? 抽象类是否可继承实体类
- *继承IObjectSafety接口,实现vb activeX控件安全性(IE不提示安全问题)