-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOverriding.cs
113 lines (81 loc) · 3.45 KB
/
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
• "FUNCTIONS" •
───────────────
• "OVERRIDING" •
▬ "Overriding" in "C#"
→ is the "Process" by which
→ a "Sub-Class" (or "Derived Class")
→ can "Provide" a "Specific Implementation"
→ for a "Method"
→ "Defined" in a "Super-Class" (or "Base Class").
♦ When a "Method"
→ is "Overridden"
→ in a "Sub-Class" ("Derived Class"),
→ it "Overrides" the "Implementation"
→ of the "Inherited Method"
→ in the "Super-Class" ("Base Class").
▬ To "Override" a "Method"
→ in a "Sub-Class" ("Derived Class"),
→ it "Must Meet"
→ the Following "Conditions":
1. The
•► "Name",
•► "Return Type", and
•► "Signature"
→ of the "Method"
→ in the "Sub-Class" ("Derived Class")
→ "Must" be "Identical"
→ to the "Method"
→ in the "Super-Class" ("Base Class").
2. The "Override" Modifier
→ "Must" be "Added"
→ in "Front"
→ of the "Sub-Class" ("Derived Class")
→ "Method Definition".
3. The "Method"
→ we are "Trying" to "Override"
→ "Must" be "Marked"
→ with the "virtual" or "abstract" Modifier
→ in the "Super-Class" ("Base Class").
▬ By "Overriding" Methods,
→ Sub-Class ("Derived Classes""
→ can Provide "Specific Behaviors"
→ or "Enhancements"
→ to "Methods Inherited"
→ from the "Super-Class" ("Base Class")
→ "Without Affecting" the "Behavior"
→ of "Other Classes"
→ that "Use" the "Super-Class" ("Base Class").
♦ This "Allows"
→ for "Greater Flexibility"
→ and "Adaptability"
→ in "Class Hierarchies" in "C#".
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀*/
namespace Csharp.functions;
public class Overriding
{
public void PrintMessage()
{
Console.WriteLine("Hello World, from Supper-Class!");
}
}
// ▬ "Sub-Class"
// → that "Extends" (":")
// → a "Super-Class" ▬
public class Overriding2 : Overriding
{
// ▬ "Overriding" the "Method" of the "Super-Class" ▬
public void PrintMessage()
{
Console.WriteLine("Hi World, from Overriding Method!");
}
public static void RunOverriding2()
{
// ▼ "Create" an "Instance" of the "Sub-Class" ▼
Overriding2 override2 = new Overriding2();
// ▼ "Accessing"
// → the "Method" of the "Super-Class"
// → or the "Overridden" Method
override2.PrintMessage();
}
}