calling to superclass/constructors questions.
hey guys, im doing a lesson on Polymorphism, and i have a basic question, not really regarding polymorphism, but the basic of a constructor question.
i have an entire group of java programs,
Employee.java (abstract) then 4 classes
commissionemployee.java
salariedemployee.java
hourlyemployee.java
basepluscommission.java
that all extend Employee. the program functions, shows the name, ssn, salary and i need to add functionality to also show the birthdate. i have added in the employee class here:
Code:
public abstract class Employee
{
private String firstName;
private String lastName;
private String socialSecurityNumber;
private String birthDate;
// six-argument constructor
public Employee( String first, String last, String ssn,
int month, int day, int year )
{
firstName = first;
lastName = last;
socialSecurityNumber = ssn;
birthDate = new Date ( month, day, year);
} // end six-argument Employee constructor
i haven't worked with "Date" before, do i declare it like i did ok? and in one of the subclasses, how do i set up the constructor, here are 2 different ways, not sure which is right, or if either is:
im guessing this:
Code:
public class CommissionEmployee extends Employee
{
private double grossSales; // gross weekly sales
private double commissionRate; // commission percentage
// six-argument constructor
public CommissionEmployee( String first, String last, String ssn, [COLOR="Red"]String birthDate[/COLOR],
double sales, double rate, )
{
super( first, last, ssn, [COLOR="Red"]birthDate[/COLOR] );
setGrossSales( sales );
setCommissionRate( rate );
} // end six-argument CommissionEmployee constructor
and not this:
Code:
public class CommissionEmployee extends Employee
{
private double grossSales; // gross weekly sales
private double commissionRate; // commission percentage
// six-argument constructor
public CommissionEmployee( String first, String last, String ssn,[COLOR="Red"] int month, int day, int year[/COLOR],
double sales, double rate, )
{
super( first, last, ssn, [COLOR="Red"]month, day, year[/COLOR] );
setGrossSales( sales );
setCommissionRate( rate );
} // end six-argument CommissionEmployee constructor