类继承接口的问题
代码如下:
using System;
interface IStorable
{
void Read();
void Write();
}
interface ITalk
{
void Talk();
void Read();
}
public class Document : IStorable, ITalk
{
// the document constructor
public Document(string s)
{
Console.WriteLine("Creating document with: {0}", s);
}
public virtual void Read()
{
Console.WriteLine("Implementing IStorable.Read");
}
public void Write()
{
Console.WriteLine("Implementing IStorable.Write");
}
void ITalk.Read()
{
Console.WriteLine("Implementing ITalk.Read");
}
public void Talk()
{
Console.WriteLine("Implementing ITalk.Talk");
}
}
public class Note : Document
{
public Note(string s):
base(s)
{
Console.WriteLine("Creating Note with: {0}", s);
}
public override void Read()
{
Console.WriteLine("Implementing Document.Read");
}
//在这里想重写Document类的ITalk.Read()
void ITalk.Read()
{
Console.WriteLine("Implementing Document.Read");
}
}
public class Tester
{
static void Main()
{
// create a document object
Document theDoc = new Document("Test Document");
IStorable isDoc = theDoc as IStorable;
if (isDoc != null)
{
isDoc.Read();
}
ITalk itDoc = theDoc as ITalk;
if (itDoc != null)
{
itDoc.Read();
}
theDoc.Read();
theDoc.Talk();
//--------------
Note n = new Note("N");
n.Read();
//--------------
Console.ReadLine();
}
}
不明白的地方在这,请指教,谢谢.
//在这里想重写Document类的ITalk.Read()
void ITalk.Read()
{
Console.WriteLine("Implementing Document.Read");
}
using System;
interface IStorable
{
void Read();
void Write();
}
interface ITalk
{
void Talk();
void Read();
}
public class Document : IStorable, ITalk
{
// the document constructor
public Document(string s)
{
Console.WriteLine("Creating document with: {0}", s);
}
public virtual void Read()
{
Console.WriteLine("Implementing IStorable.Read");
}
public void Write()
{
Console.WriteLine("Implementing IStorable.Write");
}
void ITalk.Read()
{
Console.WriteLine("Implementing ITalk.Read");
}
public void Talk()
{
Console.WriteLine("Implementing ITalk.Talk");
}
}
public class Note : Document
{
public Note(string s):
base(s)
{
Console.WriteLine("Creating Note with: {0}", s);
}
public override void Read()
{
Console.WriteLine("Implementing Document.Read");
}
//在这里想重写Document类的ITalk.Read()
void ITalk.Read()
{
Console.WriteLine("Implementing Document.Read");
}
}
public class Tester
{
static void Main()
{
// create a document object
Document theDoc = new Document("Test Document");
IStorable isDoc = theDoc as IStorable;
if (isDoc != null)
{
isDoc.Read();
}
ITalk itDoc = theDoc as ITalk;
if (itDoc != null)
{
itDoc.Read();
}
theDoc.Read();
theDoc.Talk();
//--------------
Note n = new Note("N");
n.Read();
//--------------
Console.ReadLine();
}
}
不明白的地方在这,请指教,谢谢.
//在这里想重写Document类的ITalk.Read()
void ITalk.Read()
{
Console.WriteLine("Implementing Document.Read");
}
...全文
相关推荐
详细对比php中类继承和接口继承
PHP类继承: 1、PHP类不支持多继承,也就是子类只能继承一个父类,但是支持多层次继承 比如: class frist{ public function __construct(){ echo "我是第一个类。","<br>"; } public function printer(){ echo "frist","<br>"; } } class seconds extends frist{} class third extends seconds{} $obj = new third(); $obj->printer(); 结果:这是第一个类。 frist
详解java为什么不允许类多重继承却允许接口多重继承
主要介绍了java为什么不允许类多重继承却允许接口多重继承,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
C#中实现多继承的方式:混合+接口
C#中实现多继承的方式:混合+接口 C#中实现多继承的方式:混合+接口
Delphi接口编程
Interface 以支持某种能力(或拥有某种能力) 为主体来取代多重继承
java实现多线程的两种方式继承Thread类和实现Runnable接口的方法
下面小编就为大家带来一篇java实现多线程的两种方式继承Thread类和实现Runnable接口的方法。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧


