Java Reference
In-Depth Information
15. Note that you do not catch a CloneNotSupportedException because any
such thrown exception in super.clone is caught inside the base class method
super.clone .
public class BigRecord extends Record
implements Cloneable
{
private StockItem item3;
...
public Object clone()
{
BigRecord copy =
(BigRecord) super .clone();
copy.item3 =
(StockItem)item3.clone();
return copy;
}
}
16. The heading of the class definition changes to what is shown in the following and
the method clone shown there is added. The version of Date for this chapter on the
accompanying website includes this definition of clone .
public class Date implements Cloneable
{
extra code
on website
private String month;
private int day;
private int year;
...
public Object clone()
{
try
{
return super .clone(); //Invocation of
//clone in the base class Object
}
catch (CloneNotSupportedException e)
{ //This should not happen.
return null ; //To keep compiler happy.
}
}
}
17. The heading of the class definition changes to what is shown in the following and
the method clone shown there is added. The version of Employee for this chapter
on the accompanying website includes this definition of clone .
extra code
on website
Search WWH ::




Custom Search