<<< Factory method example | Index | clone method of the Product class >>> |
A Product class implementing the Cloneable interface:
public class Product implements Cloneable
{
private String code;
private String description;
private double price;
// the code for the constructor and methods
@Override
public Object clone()
throws CloneNotSupportedException
{
// invoke Object.clone()
return super.clone();
//NOTE:
// Object.clone() method performs a "shallow copy" of the
// object, not a "deep copy" operation.
// Therefore, it may be necessary to modify one or more fields
// of the object returned by super.clone() before returning it.
}
}
<<< Factory method example | Index | clone method of the Product class >>> |