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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:24:42+00:00 2026-05-23T05:24:42+00:00

as I understood, the method clone() gives us the ability to copy object (no

  • 0

as I understood, the method clone() gives us the ability to copy object (no refernce) in Java. But I also read, that the copy is shallow. So what the point? Which ability the clone() method gives me, that a simple assingment doesn’t?

  • 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-23T05:24:42+00:00Added an answer on May 23, 2026 at 5:24 am

    The difference is that you can modify the cloned object without modifying the original object.

    Point p = new Point(1,2);
    Point p2 = p.clone();
    Point p3 = p;
    p2.x = 5;
    p3.y = 7;
    

    The change on p3 does feed back to p, while the change on p2 does not.

    Let’s see how the situation is after the individual statements (assuming 1, 2, 5, 7 would be objects):

    Point p = new Point(1,2);
    
                .-----.    .-----.
     p  ----->  |  x -+--> |  1  |
                |     |    '-----'
                |     |    .-----.
                |  y -+--> |  2  |
                '-----'    '-----'
    
    
    Point p2 = p.clone();
    
                .-----.    .-----.    .-----.
     p  ----->  |  x -+--> |  1  | <--+- x  |  <----- p2
                |     |    '-----'    |     |
                |     |    .-----.    |     |
                |  y -+--> |  2  | <--+- y  |
                '-----'    '-----'    '-----'
    
    Point p3 = p;
    
                .-----.    .-----.    .-----.
     p  ----->  |  x -+--> |  1  | <--+- x  |  <----- p2
                |     |    '-----'    |     |
                |     |    .-----.    |     |
     p3 ----->  |  y -+--> |  2  | <--+- y  |
                '-----'    '-----'    '-----'
    
    
    p2.x = 5;
    
                .-----.    .-----.    .-----.    .-----.
     p  ----->  |  x -+--> |  1  |    |  x -+--> |  5  |
                |     |    '-----'    |     |    '-----'
                |     |    .-----.    |     |
     p3 ----->  |  y -+--> |  2  | <--+- y  |  <----- p2
                '-----'    '-----'    '-----'
    
    
    p3.y = 7;
    
                .-----.    .-----.    .-----.    .-----.
     p  ----->  |  x -+--> |  1  |    |  x -+--> |  5  |
                |     |    '-----'    |     |    '-----'
                |     |    .-----.    |     |
     p3 ----->  |  y  |    |  2  | <--+- y  |  <----- p2
                '--+--'    '-----'    '-----'
                   |     .-----.
                   '---> |  7  |
                         '-----'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is clone() in java a shallow copy? Eventually this gets to the clone() method
I understand that static method inheritance is not supported in C#. I have also
I understand that any init... method initializes a new object and that NSString stringWithString
According to Java documentation, the read() method returns: -1 if there is no more
I thought I understood what the default method does to a hash... Give a
I understand that .NET FileStream's Flush method only writes the current buffer to disk,
Am I correct to understand that the abort() method for XMLHttpRequest objects is only
I read django.contrib.sessions.backend.file today, in the save method of SessionStore there is something as
I've been implementing a GWT application that calls a REST-service (which we're also developing).
I thought I understood the basics of pointers, but after checking out some documentation

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.