M
Mike P
I'm trying to write my first project using inheritance, and I'm not sure
whether I'm going about it the right way (excuse me if my terminology
isn't quite right).
If I have a class called Person which is used to set variables DOB,
Address, MaritalStatus, and then Employee which inherits the Person
class and extends it with Department, NI Number and Position, I'm not
clear on how to instantiate these classes or what to put in the
constructors.
This is my code where I am instantiating them :
Person clsPerson = new Person(DOB, Address, MaritalStatus);
Employee clsEmployee = new Employee(Department, NINumber, Position);
This is the beginning of my Person class :
public class Person
{
private DateTime mDOB;
private string mAddress;
private string mMaritalStatus;
public Person(DateTime DOB, string Address, string MaritalStatus)
{
mDOB = DOB;
mAddress = Address;
mMaritalStatus = MaritalStatus;
}
And this is the beginning of my Employee class :
public class Employee : Person
{
private DateTime mDOB;
private string mAddress;
private string mMaritalStatus;
private string mDepartment;
private string mNINumber;
private string mPosition;
public Employee(string Department, string NINumber, string Position) :
base(DOB, Address, MaritalStatus)
{
mDepartment = Department;
mNINumber = NINumber;
mPosition = Position;
}
Can somebody please tell me where I'm going wrong with this?
Cheers,
Mike
whether I'm going about it the right way (excuse me if my terminology
isn't quite right).
If I have a class called Person which is used to set variables DOB,
Address, MaritalStatus, and then Employee which inherits the Person
class and extends it with Department, NI Number and Position, I'm not
clear on how to instantiate these classes or what to put in the
constructors.
This is my code where I am instantiating them :
Person clsPerson = new Person(DOB, Address, MaritalStatus);
Employee clsEmployee = new Employee(Department, NINumber, Position);
This is the beginning of my Person class :
public class Person
{
private DateTime mDOB;
private string mAddress;
private string mMaritalStatus;
public Person(DateTime DOB, string Address, string MaritalStatus)
{
mDOB = DOB;
mAddress = Address;
mMaritalStatus = MaritalStatus;
}
And this is the beginning of my Employee class :
public class Employee : Person
{
private DateTime mDOB;
private string mAddress;
private string mMaritalStatus;
private string mDepartment;
private string mNINumber;
private string mPosition;
public Employee(string Department, string NINumber, string Position) :
base(DOB, Address, MaritalStatus)
{
mDepartment = Department;
mNINumber = NINumber;
mPosition = Position;
}
Can somebody please tell me where I'm going wrong with this?
Cheers,
Mike