Java Reference
In-Depth Information
17. Yes, all static variables are inherited. Because a defined constant is a form of static
variable, it is inherited. So, the class
HourlyEmployee
inherits the constant
STANDARD_HOURS
from the class
Employee
.
18.
public boolean
equals(Object otherObject)
//This is NOT the right way to define equals.
{
if
(otherObject ==
null
)
return false
;
else if
(!(otherObject instanceof Employee))
return false
;
else
{
Employee otherEmployee = (Employee)otherObject;
return
(name.equals(otherEmployee.name)
&& hireDate.equals(otherEmployee.hireDate));
}
}
19.
A version of the
HourlyEmployee
class with this definition of
equals
is in the
subdirectory
improvedEquals
of the
ch07
directory on the accompanying CD.
extra code
on CD
public boolean
equals(Object otherObject)
{
if
(otherObject ==
null
)
return false
;
else if
(getClass() != otherObject.getClass())
return false
;
else
{
HourlyEmployee otherHourlyEmployee =
(HourlyEmployee)otherObject;
return
(
super
.equals(otherHourlyEmployee)
&& (wageRate == otherHourlyEmployee.wageRate)
&& (hours == otherHourlyEmployee.hours));
}
}
20.
A version of the
SalariedEmployee
class with this definition of
equals
is in the
subdirectory
improvedEquals
of the
ch07
directory on the accompanying CD.
extra code
on CD
public boolean
equals(Object otherObject)
{
if
(otherObject ==
null
)
return false
;
else if
(getClass() != otherObject.getClass())
return false
;
else
{