What is object cloning in vb6 or java? In what situation do we use a clone? What does cloning objects mean? Can any one tell me with example please.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Cloning is actually copying the object data into a new object.
This example doesn’t clone the data:
If
Foohas a memberaand you changep.atheno.aalso changes because bothpandopoint to the same object.However,
In this case if you change
p.atheno.aremains the same because they actually point to separate objects.There are actually two different ways you can clone: shallow clone or deep clone.
A shallow clone just makes a new object and copies the members into the new object. This means that if one of the members is actually a pointer to another object then that object will be shared between the old object and new object.
A deep clone actually goes through and clones all the members into the new object. That way the objects are complete copies of all the data.