Java Reference
In-Depth Information
public class Employee implements Cloneable
{
private String name;
private Date hireDate;
...
public Object clone()
{
try
{
Employee copy =
(Employee) super .clone();
copy.hireDate =
(Date)hireDate.clone();
return copy;
}
catch (CloneNotSupportedException e)
{ //This should not happen.
return null ; //To keep compiler happy.
}
}
}
18.
The heading of the class definition changes to what is shown in the following and
the method clone shown there is added. Note that you do not catch a CloneNot-
SupportedException because any such thrown exception in super.clone is
caught inside the base class method super.clone . The version of HourlyEmployee
for this chapter on the accompanying CD includes this definition of clone .
extra code
on CD
public class HourlyEmployee extends Employee
implements Cloneable
{
private double wageRate ;
private double hours;
...
public Object clone()
{
HourlyEmployee copy =
(HourlyEmployee) super .clone();
return copy;
}
}
19.
It would still be legal. An outer class has access to all the private members of an
inner class.
20.
Yes, they can be omitted, but the reason is that it indicates package access, and in
a private inner class, all privacy modifiers, including package access, are equiva-
lent to public. (Note that the situation for public inner classes will be different.)
Search WWH ::




Custom Search