Java Reference
In-Depth Information
return super
.clone();
}
catch
(CloneNotSupportedException e)
{
//This should not happen.
return null
;
//To keep compiler happy.
}
}
}
13.
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
PricedItem
extends
StockItem
implements
Cloneable
{
private double
price;
...
public
Object clone()
{
return super
.clone();
}
}
14.
public class
Record
implements
Cloneable
{
private
StockItem item1;
private
StockItem item2;
private
String description;
...
public
Object clone()
{
try
{
Record copy =
(Record)
super
.clone();
copy.item1 =
(StockItem)item1.clone();
copy.item2 =
(StockItem)item2.clone();
return
copy;
}
catch
(CloneNotSupportedException e)
{
//This should not happen.
return null
;
//To keep compiler happy.
}
}
}