I'm trying to understand a piece of code my prof gave me regarding constructors and inheritance.
Below is an 'Employee' Class where variables are created and a constructed is created to initialize said variables. This part I get pretty well.
public abstract class Employee {
private int employeeID;
private String firstName;
private String lastName;
private ArrayList<Paycheck> listOfPaychecks;
Employee(int employeeID, String firstName, String lastName, `
ArrayList<Paycheck> listOfPaychecks) {
this.employeeID=employeeID;
this.firstName=firstName;
this.lastName=lastName;
this.listOfPaychecks=listOfPaychecks;
}
Below, she provided a different class named SalariedEmployee which extends the Employee class. She created a variable annualSalary.
This is where I'm getting confused, I see that she created two constructors.
public class SalariedEmployee extends Employee {
double annualSalary;
SalariedEmployee(SalariedEmployee s) {
super(s.getEmployeeID(), s.getFirstName(), s.getLastName(),
s.getListOfPaychecks());
this.annualSalary = s.annualSalary;
}
SalariedEmployee(int employeeID, String firstName, String lastName,
ArrayList<Paycheck> listOfPaychecks,
double annualSalary) {
super(employeeID, firstName, lastName, listOfPaychecks);
this.annualSalary = annualSalary;
}
What is the point of creating two constructors? I see the first one, she created a variable 's' and it's getting the variables from the Employee class' constructor. Is this just to set the s variable to the returning variables in the Employee class?
Can someone help me understand why do we create two constructors? I'm sorry if my vocab is not that well. I am still learning.