Reputation: 1
In the parent class, I have this:
public String toString(String employeetype) {
return super.toString() + "\n" + employeetype + employeeno + " Hired on: "
+ DateFormat.getDateInstance().format(datehired) + " ";
}
and in the child classes, I have these two:
public String toString() {
return super.toString("SalariedEmployee") + "[salary= " + this.pay() + "]";
}
public String toString() {
return super.toString("HourlyEmployee") + "[salary= " + this.pay() + "]";
}
When I call them, they print out:
Person [name=John Doe, ssno=012345678, gender=Male]
SalariedEmployeenull Hired on: Feb 25, 2014 [salary= $0.0 Per Week]
Person [name=John Doe, ssno=012345678, gender=Male]
HourlyEmployeenull Hired on: Feb 25, 2014 [salary= $0.0 Per Hour from ]
So why does say SalariedEmployeenull and HourlyEmployeeNull instead of SalariedEmployee and HourlyEmployee? Is there a way to fix this while keeping the code in this format? If not, why can't I pass as an argument? I'd like to know how it works. Thanks for your help.
Upvotes: 0
Views: 687
Reputation: 20163
So why does say SalariedEmployeenull and HourlyEmployeeNull instead of SalariedEmployee and HourlyEmployee?
Because employeeno
is null
. And to make your output clearer, there should be a space between it and employeetype
.
Why is employeeno
null? We can't know until you give us some more information.
Upvotes: 1