using System;
class ExplicitInterface
{
interface readFile
{
void Read();
void Write();
}
interface writeFile
{
void View();
void Read();
}
public class Document : readFile , writeFile
{
public Document(string doc)
{
Console.WriteLine("Creating a document with : "+doc);
}
public virtual void Read()
{
Console.WriteLine("Reading from Read Method in Interface readFile");
}
public void Write()
{
Console.WriteLine("Writing in Write Method in Interface readFile");
}
void writeFile.Read()
{
Console.WriteLine("Reading from Read Method in Interface writeFile");
}
public void View()
{
Console.WriteLine("Viewing from View Method in Interface writeFile");
}
}
public void CreateDoc()
{
Document doc1 = new Document("This Document is getting written\n in the document created.");
readFile rFile = doc1 as readFile;
if(rFile != null)
rFile.Read();
writeFile wFile = (writeFile)doc1;
if(wFile != null)
wFile.Read();
doc1.Read();
doc1.View();
}
static void Main()
{
ExplicitInterface ei = new ExplicitInterface();
ei.CreateDoc();
Console.ReadKey();
}
}
Output:-
No comments:
Post a Comment