Skip to content

Commit e7431b6

Browse files
authored
Method Overriding
1 parent b702e6e commit e7431b6

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

MethodOverriding.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System;
2+
using System.Diagnostics;
3+
4+
namespace TestApplication
5+
{
6+
7+
/* Polymorphism --- Example of Method Overriding ---
8+
9+
When derived class has a definition for one of the member functions of
10+
the base class. that base function is said to be overriden.
11+
12+
13+
14+
*/
15+
16+
public class Vehicle
17+
{
18+
public virtual void show()
19+
{
20+
Console.WriteLine("Base Class");
21+
}
22+
}
23+
24+
public class Honda : Vehicle
25+
{
26+
public override void show()
27+
{
28+
Console.WriteLine("Derived Class");
29+
}
30+
}
31+
32+
internal static class Polymorphism
33+
{
34+
public static void Main(string[] args)
35+
{
36+
var vehicle = new Vehicle();
37+
vehicle.show();
38+
39+
vehicle = new Honda();
40+
vehicle.show();
41+
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)