-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInheritance.cs
More file actions
89 lines (82 loc) · 2.18 KB
/
Inheritance.cs
File metadata and controls
89 lines (82 loc) · 2.18 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CSharpProgramming
{
/// <summary>
/// Inheritance-Code Reusability
/// Types-Single,Multi-level,Hybrid,Hierarchial
/// Multiple Inheritance-Not supported-instead Interfaces are used
/// protected access specifier
/// </summary>
/// BASE CLASS
internal class Employee
{
protected int EID;
protected string EName;
protected int TDID;
protected string TDName;
protected void Display()
{
Console.WriteLine("BASE CLASS");
}
}
/// <summary>
/// Child Class - Department
/// Single-level
/// </summary>
internal class Department:Employee
{
protected int DID;
protected string DName;
}
/// <summary>
/// Hierarchial Inheritance
/// </summary>
internal class TrainingDepartment : Employee
{
public void GetTDetails()
{
base.Display();
TDID = 101;
TDName = "DOTNET";
Console.WriteLine($"TDID is {TDID} and TDName is {TDName}");
}
}
/// <summary>
/// Multi-level inheritance
/// </summary>
internal class Admin:Department
{
public void GetEmployeeDetails()
{
EID = 100;
EName = "John";
DID = 10;
DName = "Developer";
Console.WriteLine($"Employee {EID}'s name is {EName}");
Console.WriteLine($"{EName} is in {DName} Department");
}
}
/// <summary>
/// Accessing the base from derived class
/// </summary>
internal class Inheritance
{
public static void Main()
{
//Single-level
// Department department = new Department();
// department.GetEmployeeDetails();
// department.Display();
//Multi-level
Admin admin = new Admin();
admin.GetEmployeeDetails();
//Hierarchial
TrainingDepartment trainingDepartment = new TrainingDepartment();
trainingDepartment.GetTDetails();
}
}
}