Java Reference
In-Depth Information
22
this .baseSalary = baseSalary;
23
}
24
25
// set base salary
26
public void setBaseSalary( double baseSalary)
27
{
28
if (baseSalary < 0.0 )
29
throw new IllegalArgumentException(
30
"Base salary must be >= 0.0" );
31
32
this .baseSalary = baseSalary;
33
}
34
35
// return base salary
36
public double getBaseSalary()
37
{
38
return baseSalary;
39
}
40
41
// calculate earnings
42
@Override
43
public double earnings()
44
{
45
// not allowed: commissionRate and grossSales private in superclass
return baseSalary + ( commissionRate * grossSales );
46
47
}
48
49
// return String representation of BasePlusCommissionEmployee
50
@Override
51
public String toString()
52
{
53
// not allowed: attempts to access private superclass members
return String.format(
"%s: %s %s%n%s: %s%n%s: %.2f%n%s: %.2f%n%s: %.2f" ,
"base-salaried commission employee" , firstName , lastName ,
"social security number" , socialSecurityNumber ,
"gross sales" , grossSales , "commission rate" , commissionRate ,
"base salary" , baseSalary);
54
55
56
57
58
59
60
}
61
} // end class BasePlusCommissionEmployee
BasePlusCommissionEmployee.java:46: error: commissionRate has private access
in CommissionEmployee
return baseSalary + (commissionRate * grossSales);
^
BasePlusCommissionEmployee.java:46: error: grossSales has private access in
CommissionEmployee
return baseSalary + (commissionRate * grossSales);
^
BasePlusCommissionEmployee.java:56: error: firstName has private access in
CommissionEmployee
"base-salaried commission employee", firstName, lastName,
^
Fig. 9.8 | private superclass members cannot be accessed in a subclass. (Part 2 of 3.)
Search WWH ::




Custom Search