-
clone method
here is one of the assignment that i am not sure. let me know if you know something.
Suppose that the Foo class has a clone method. what typically happens when an call x=(Foo) y.clone(); is given for two Foo objects?
A) x is set to refer to a copy of y's object
B) x is set to refer to the same object that y refers to
C) Compiler error
D) run-time error
-
Re: clone method
Hi,
An Object's implementation of Clone method checks to see whether the object on which clone was invoked implements the Cloneable interface.
If the object does not, the method throws a CloneNotSupportedException.
If the object on which clone was invoked does implement the Cloneable interface, Object's implementation of the clone method creates an object of the same type as the original object and initializes the new object's member variables to have the same values as the original object's corresponding member variables.
So the correct answer must be (A)
Happy coding