Question:
The purpose of Cloneable interface is to tell JVM that this class is eligible for cloning. Note that the class Object doesn't implement , hence if you call the Object class "clone()" method without implementing Cloneable interface, a CloneNotSupportedException will be thrown.
How do I implement Cloneable interface, in my Taxpayer class below. Since I am doing An override of the clone method in this class. I am already implementing Taxable interface. Would it be possible to implement Taxable interface and Coneable interface?
public class Taxpayer implements Taxable { private String iName = ""; private float iIncome = 0; private double iTax = 0; private boolean iclone = false; public Taxpayer(String name, double income) { iName = name; iIncome = (float) income; } public Object clone() { Taxpayer clone = null; try{ iclone = true; clone = (Taxpayer) super.clone(); } catch (CloneNotSupportedException xcp ) { clone = null;} return clone; } }
Thank you,