While explaining the item 11: Override clone()
judiciously it says - The "only" way a superclass can provide this functionality is to return an object obtained by calling super.clone
. If a clone method returns an object created by a constructor, it will have the wrong class.
Why will it have a wrong class? Can't every object's clone method call its own constructor?
In java you have to call the constructor to allocate the memory, right? If we aren't calling the constructor anytime during the whole chain of
super.clone()
, then who's allocating the memory for the clone?