What is instanceof of a cloned object?

clone, java

Solution

The same as the initiator by means the original parent class whic always uses Object.clone() by calling the super.clone(). For more visit

http://howtodoinjava.com/2012/11/08/a-guide-to-object-cloning-in-java/

https://www.artima.com/objectsandjava/webuscript/ClonCollInner1.html

Problem

If a class A makes public Object's `clone()` method: ``` @Override public Object clone() { return super.clone(); } ``` What will be the `instanceof` (or `getClass()`) of an instance of A created using `clone()`? What about instances of `class B extends A` created using the `clone()` method ? EDIT Clarification: I ask this because even before compiling, Eclipse java editor requires to cast the returned clone() instance to the assigned object. Which suggest that the returned class is `Object` (which technically it is, but all the answers so far say the class should be A) ``` A original = new A(); A cloned1 = original.clone(); // Eclipse marks this as error A cloned2 = (A) original.clone(); // This is OK ```

Original source