What is Inheritance or How to define Inheritance in C#
Inheritance
is the most feature in the object oriented programming.
Inheritance
helps not do the repetition of code the same code in the multiple places when dealing
with
different
classes which have several features in
common and are related to each other. Even they are
different
subclasses of the same type, each with its own distinguishing feature
Declared and Define Inherited Class
Parent/Base
Class
public
Class Employee
{
protected
int EmployeeNumber;
protected
string EmployeeFirstName;
protected
string EmployeeLastname;
protected
float Salary;
Protected
void WorkAssigned()
{
}
}
//Program
Manager class inheriting from Employee
class
Public
Class TechnicalManager:Employee
{
Public
void ProgramManagerWorkAssigned()
{
}
}
//Program
Technical Manager class inheriting from
Employee class
Public
Class TechnicalManager:Employee
{
Public
void TechnicalManagerWorkAssigned()
{
}
}
example,
Program Manager and Technical Manager ,Engineer
are all employees of a Software Company .
When
we are writing an application to simulate the Employee Management System, how
would you specify that
Program
Manager and Technical Manager and Engineer have several features that are the
same, but also
other
features that are different? For example, they all have an employee reference employee number and a name and so on, also
each one has different responsibilities. When we want to define class of Program
Manager and Technical Manager and Engineer each has to be inheriting the
employee. So we don’t need to define the common features in all the classes.
In
C# inheritance is implemented by using “:”
No comments:
Post a Comment