39
1
using System;
2
3
public class Program
4
{
5
public static void Main()
6
{
7
IFile file1 = new FileInfo();
8
file1.ReadFile();
9
file1.WriteFile("content");
10
file1.DisplayName();
11
12
FileInfo file2 = new FileInfo();
13
//file2.DisplayName(); //compile-time error
14
}
15
}
16
17
interface IFile
18
{
19
void ReadFile();
20
void WriteFile(string text);
21
22
void DisplayName()
23
{
24
Console.WriteLine("IFile");
25
}
26
}
27
28
class FileInfo : IFile
29
{
30
public void ReadFile()
31
{
32
Console.WriteLine("Reading File");
33
}
34
35
public void WriteFile(string text)
36
{
37
Console.WriteLine("Writing to file");
38
}
39
}
Cached Result
Reading File
Writing to file
IFile
Writing to file
IFile