-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoverriding.cs
58 lines (45 loc) · 897 Bytes
/
overriding.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System;
class Program
{
static void Main(string[] args)
{
Base bRef = new Base();
Derive1 d1 = new Derive1();
Derive2 d2 = new Derive2();
bRef.who();
d1.who();
d1.whos();
d2.who();
d2.whos();
Console.WriteLine();
bRef = d1;
bRef.who();
bRef = d2;
bRef.who();
Console.ReadLine();
}
}
class Base
{
public virtual void who(){
Console.WriteLine("Who() in Base");
}
}
class Derive1 : Base
{
public override void who(){
Console.WriteLine("Who() in Derive1");
}
public void whos(){
Console.WriteLine("Whos() in Derive1");
}
}
class Derive2 : Base
{
public override void who(){
Console.WriteLine("Who() in Derive2");
}
public void whos(){
Console.WriteLine("Whos() in Derive2");
}
}