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 6997843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:20:05+00:00 2026-05-27T20:20:05+00:00

Kindly clarify me for the following questions. Does super.clone() perform Deep copying or shallow

  • 0

Kindly clarify me for the following questions.

  1. Does super.clone() perform Deep copying or shallow copying?
  2. In the below example, why don’t we need class CompositeObjCloneMe as cloneable? Does cObj won’t be cloned while trying to clone CloneMe object?
    Note: Even making CompositeObjCloneMe as cloneable doesn’t have any impact on output.
  3. Why the output is behaving like shallow copying (Not deep coppying) since program is setting primitive value(setCObjValue = 100) of a class? (where primitive fields are deeply copied)
  4. Is it immutable Objects && primitives are inherently deeply copied?

    class CloneMe implements Cloneable {
        private CompositeObjCloneMe cObj;
    
        public CloneMe() {
            cObj = new CompositeObjCloneMe();
          }
    
        public void setCObjValue(int myOwnDt) {
            this.cObj.setObj(myOwnDt);
        }
        public int getCObjValue() {
            return this.cObj.getObj();
        }
        //Clone
        public Object clone() throws CloneNotSupportedException {
        return super.clone();
        }
    }
    
    class CompositeObjCloneMe {//implements Cloneable{
        private int value = 20;
        public void setObj(int i){
            value = i;
        }
        public int getObj(){
            return value;
        }
    //  public Object clone() throws CloneNotSupportedException{
    //      return super.clone();
    //  }
    }
    
    
    public class CloneTest {
        public static void main(String arg[]) {
            CloneMe realObj = new CloneMe();
            try {
                CloneMe cloneObj = (CloneMe) realObj.clone();
                realObj.setCObjValue(100);
                System.out.println(realObj.getCObjValue()  + "   " + cloneObj.getCObjValue());
            } catch (CloneNotSupportedException cnse) {
                System.out.println("Cloneable should be implemented. " + cnse);
            }
        }
    }
    

OUTPUT: 100 100

  • 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-05-27T20:20:06+00:00Added an answer on May 27, 2026 at 8:20 pm

    1) javadoc to the rescue:

    […] Thus, this method performs a “shallow copy” of this object, not
    a “deep copy” operation.

    2) Because clone doesn’t call clone recursively. It’s a shallow clone. It just creates a new object with the same references as the original one, and copies of primitive fields.

    3) I don’t understand what you mean. Primitive are not deeply copied. They don’t reference anything, so there’s nothing deep to copy.

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

Sidebar

Related Questions

Can someone kindly enlighten me why the following code of mine does not work?
Kindly read the following code as an example (pay attention to the padding-bottom of
Please kindly help me in the following, I have $sub = C:\views\sght\gzad\text\hksdk\akldls\hool.java = C:\views\sght\bdsk\text\hksdfg\sdjks\same.java
Would someone kindly explain why the following bit of code works, I've tested it
I would really apreciate if some one kindly clarify my confusion. I'm doing my
Kindly give an detailed explanation too. How does it work ?
Kindly get me the limits of following things in sqlite of iphone No of
Previous question linky: MySQL Left Joins Very kindly we got the following code working:
Kindly don't mind my question as it is a little theoretical. Last week I
Can someone kindly explain how the following python code is working? This code is

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.