Constructors
I have a problem with the output of this program
this program consist of three classes
the fist one is
package c;
publicclass CommissionEmployee4
{
private String firstName;
private String lastName;
private String socialSecurityNumber;
privatedouble grossSales;// gross weekly sales
privatedouble commissionRate;// commission percentage
// five-argument constructor
public CommissionEmployee4( String first, String last, String ssn,
double sales,double rate )
{
// implicit call to Object constructor occurs here
firstName = first;
lastName = last;
socialSecurityNumber = ssn;
setGrossSales( sales );// validate and store gross sales
setCommissionRate( rate );// validate and store commission rate
System.out.printf(
"\nCommissionEmployee4 constructor:\n%s\n",this );
}// end five-argument CommissionEmployee4 constructor
// return first name
public String getFirstName()
{
return firstName;
}// end method getFirstName
// return last name
public String getLastName()
{
return lastName;
}// end method getLastName
// return social security number
public String getSocialSecurityNumber()
{
return socialSecurityNumber;
}// end method getSocialSecurityNumber
// set gross sales amount
publicvoid setGrossSales(double sales )
{
grossSales = ( sales < 0.0 ) ? 0.0 : sales;
}// end method setGrossSales
// return gross sales amount
publicdouble getGrossSales()
{
return grossSales;
}// end method getGrossSales
// set commission rate
publicvoid setCommissionRate(double rate )
{
commissionRate = ( rate > 0.0 && rate < 1.0 ) ? rate : 0.0;
}// end method setCommissionRate
// return commission rate
publicdouble getCommissionRate()
{
return commissionRate;
}// end method getCommissionRate
// return String representation of CommissionEmployee4 object
public String toString()
{
return String.format("%s: %s %s\n%s: %s\n%s: %.2f\n%s: %.2f",
"commission employee", getFirstName(), getLastName(),
"social security number", getSocialSecurityNumber(),
"gross sales", getGrossSales(),
"commission rate", getCommissionRate() );
}// end method toString
}// end class CommissionEmployee4
the second class is inherited from the fist and inside its constructor ,explicitly call the construcror of the super class
package c;
publicclass BasePlusCommissionEmployee5extends CommissionEmployee4
{
privatedouble baseSalary;// base salary per week
// six-argument constructor
public BasePlusCommissionEmployee5( String first, String last,
String ssn,double sales,double rate,double salary )
{
super( first, last, ssn, sales, rate );
setBaseSalary( salary );// validate and store base salary
System.out.printf(
"\nBasePlusCommissionEmployee5 constructor:\n%s\n",this );
}// end six-argument BasePlusCommissionEmployee5 constructor
// set base salary
publicvoid setBaseSalary(double salary )
{
baseSalary = ( salary < 0.0 ) ? 0.0 : salary;
}// end method setBaseSalary
// return base salary
publicdouble getBaseSalary()
{
return baseSalary;
}// end method getBaseSalary
// return String representation of BasePlusCommissionEmployee5
public String toString()
{
return String.format("%s %s\n%s: %.2f","base-salaried",
super.toString(),"base salary", getBaseSalary() );
}// end method toString
}// end class BasePlusCommissionEmployee5
the third class is that contain the main method and print and show how the contructors of the subclass call the constructor of the superclass
package c;
publicclass ConstructorTest{
publicstaticvoid main(String[] args){
CommissionEmployee4 employee1 =new CommissionEmployee4(
"Bob","Lewis","333-33-3333", 5000, .04 );
System.out.println();
BasePlusCommissionEmployee5 employee2 =
new BasePlusCommissionEmployee5(
"Lisa","Jones","555-55-5555", 2000, .06, 800 );
System.out.println();
BasePlusCommissionEmployee5 employee3 =
new BasePlusCommissionEmployee5(
"Mark","Sands","888-88-8888", 8000, .15, 2000 );
}
}
But the problem with me is abou this output
**************************the output*****************************
CommissionEmployee4 constructor:
commission employee: Bob Lewis
social security number: 333-33-3333
gross sales: 5000.00
commission rate: 0.04
CommissionEmployee4 constructor:
base-salaried commission employee: Lisa Jones
social security number: 555-55-5555
gross sales: 2000.00
commission rate: 0.06
base salary: 0.00
BasePlusCommissionEmployee5 constructor:
base-salaried commission employee: Lisa Jones
social security number: 555-55-5555
gross sales: 2000.00
commission rate: 0.06
base salary: 800.00
CommissionEmployee4 constructor:
base-salaried commission employee: Mark Sands
social security number: 888-88-8888
gross sales: 8000.00
commission rate: 0.15
base salary: 0.00
BasePlusCommissionEmployee5 constructor:
base-salaried commission employee: Mark Sands
social security number: 888-88-8888
gross sales: 8000.00
commission rate: 0.15
base salary: 2000.00
************************************************** **************
why the object employee2 print this statment> (base salary: 0.00)
i know that when we create the employee2 object:first it call the CommissionEmployee4 constructor so it prints its values (i.e. "Lisa", "Jones", "555-55-5555", 2000, .06, 800 ) so why it print the base salary although there isn't in the CommissionEmployee4 constructor base salary

