class CoffeeCup implements Cloneable {
public Object clone() {
try {
return super.clone();
}
catch (CloneNotSupportedException e) {
// This should never happen
throw new InternalError(e.toString());
}
}
}
in another class i used:
CoffeeCup original = new CoffeeCup();
original.add(75); // Original now contains 75 ml of
coffee
CoffeeCup copy = (CoffeeCup) original.clone();
Now i got exact copy of CoffeeCup.
my question is: how the application is creating an subclass object(CoffeeCup) when I call super.clone().
As per my understanding if we call super.clone() that means we are calling Object.clone() -- if that is the case how it is creating the object of sub class?
Is there any underlying implementation that Object class uses for creating the subclass object?