Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8867535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:03:38+00:00 2026-06-14T17:03:38+00:00

I read this post today about deep copying and had a few questions: In

  • 0

I read this post today about deep copying and had a few questions:

In the first code, the author says adding an (integer) object to a clone does not appear in the original. Why is this so? As I understand, cloning basically creates an object with the same references to objects as the original.

Why isn’t a change in the clone reflected back in the original?

Doesn’t clone share the same reference as the Original?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T17:03:40+00:00Added an answer on June 14, 2026 at 5:03 pm

    When you do a clone of an Object 'A', you are creating a new Object 'B' (with the same references to objects) but in a different memory address. Thus, when you modify the object ‘A’ you are not accessing the same memory address of the Object 'B'. Therefore, changes in the clone do not reflect back in the original object and vice-versa.

    Shallow Copy

    Generally, the clone method of an object, creates a new instance of the same class and copies all the fields to the new instance and returns it. This is nothing but shallow copy. Object class provides a clone method and provides support for the shallow copy. It returns ‘Object’ as the type and you need to explicitly cast back to your original object.

    Deep Copy

    When you need a deep copy then you need to implement it yourself. When the copied object contains some other object its references are copied recursively in the deep copy. When you implement a deep copy be careful as you might fall for cyclic dependencies. If you don’t want to implement deep copy yourself then you can go for serialization. It does implement deep copy implicitly and gracefully handling cyclic dependencies.

    (source about the information)

    Here an illustrative example:

    Shallow

    Before Copy
    Shallow Copying
    Shallow Done

    Deep:

    Before Copy
    Deep Copying
    (source: wikimedia.org)

    Deep Done

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I read today this blog post http://www.andrewrollins.com/2009/06/21/mysql-join-performance/ about join performance. As seen, join could
I read this post where the author advices to store session files in a
Okay so I read this post http://facebook.stackoverflow.com/questions/10373897/deleting-a-previosly-posted-article-with-opengraph-or-check-if-said-article-has but I'm using the news.reads action type.
I was reading about buffer, stack and heap overflows. I read this post as
On this post , I read about the usage of XMPP. Is this sort
I read this comment in the OpenID post on the stackoverflow blog. Kibbee says
I read at a few places (in the doc and in this blog post
I've read every post about this issue, but nothing solved the problem. I'll be
I've read the blog post at letitcrash.com about Play-mini and Akka ( this one
I read this post about card shuffling and in many shuffling and sorting algorithms

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.