类继承接口的问题

maroon maroon 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
代码如下:
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");
}

...全文
评论 7
收藏 已收藏
分享
返回顶部
maroon
C# 111,128 成员 642,536 内容