Can you actually compile that code? There are at least two errors I can see that should be reported at compile time: 1. CloneNotSupportedException is not handled or thrown and 2. the method does not have a return statement.
I'm not sure how cloning is actually implemented because it is implemented as a native method.
But it returns copy of current object, I know that, but I don't understand why there is used super.clone() instead of logical this.clone().
this.clone() would be recursive call and would be of no real use. The shallow copying is somehow implemented as a native method. It is defined in the Object class. You extended it (implicity tho'). super.clone() is going to invoke it.
* There is no such thing as the "parent" object. Perhaps this is the root of your confusion.
* Nadeem was quoting the relevent part of the documentation when he wrote that "x.clone().getClass() == x.getClass()", and later the documentation repeats, "this method creates a new instance of the class of this object".
This is the documentation in class Object, so you should realize the implication of that: any subclass (direct or indirect) should obey this as well!
Pavel, by "works" I take it that you mean it compiles successfully.
True, the code you gave will compile successfully because compile-time checking of casts is limited--the most the compiler can do is to make sure that the reference being cast is at least a supertype. Since Object is a supertype of the Test class, the compiler will allow the statement. Another check will be made at runtime to ensure that the cast is actually valid. If the runtime check fails, a ClassCastException will be thrown. For the code you gave, however, the runtime check will not even be made because a checked exception (CloneNotSupportException) will be thrown by Object.clone() first.