类继承接口的问题
代码如下:
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");
}