-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmethodHiding.cs
50 lines (47 loc) · 1.37 KB
/
methodHiding.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
using System;
namespace Method_Hiding
{
class Program
{
static void Main(string[] args)
{
FullTimeEmployee fte = new FullTimeEmployee();
fte.FirstName = "Fulltime";
fte.LastName = "Employee";
fte.PrintFullName();
//PartTimeEmployee pte = new PartTimeEmployee();
//Parent class reference variables can point to child class objects
//a parent class reference variable can point to a child class object
Employee pte = new PartTimeEmployee();
pte.FirstName = "PartTime";
pte.LastName = "Employee";
//Typecasting
//((Employee)pte).PrintFullName();
}
}
public class Employee
{
public string FirstName;
public string LastName;
public void PrintFullName()
{
Console.WriteLine(FirstName+" "+LastName);
}
}
public class PartTimeEmployee : Employee
{
//use new keyword to hide abase class member
public new void PrintFullName()
{
Console.WriteLine(FirstName + " " + LastName);
}
}
public class FullTimeEmployee : Employee
{
public new void PrintFullName()
{
//base.PrintFullName();
// Console.WriteLine(FirstName + " " + LastName+"- Contractor");
}
}
}