Results 1 to 2 of 2
  1. #1
    Wnt2bsleepin is offline Senior Member
    Join Date
    Feb 2012
    Posts
    219
    Rep Power
    3

    Default Copy Constructor with Shallow Copy

    I am supposed to make a constructor that makes a shallow copy. Can anyone elaborate on specifically that is? What makes it different than a regular copy?

  2. #2
    Daimoth's Avatar
    Daimoth is offline Member
    Join Date
    Jul 2011
    Posts
    34
    Rep Power
    0

    Default Re: Copy Constructor with Shallow Copy

    A shallow copy merely copies the reference to data, whereas a deep copy duplicates the data itself.

    A related term is the lazy copy, which takes advantage of the speed of the shallow copy when at all possible, and becomes a deep copy when necessary.

    If you change the value of a shallow copied object, both will reflect the change; not so with a deep copy, which are independent.

    All objects have a clone() method which returns a deep copy of the object, apparently.

Similar Threads

  1. Collections copy constructors guaranteed shallow?
    By kjkrum in forum Advanced Java
    Replies: 3
    Last Post: 01-23-2012, 08:34 AM
  2. What is the point of a copy constructor?
    By ozzyman in forum New To Java
    Replies: 3
    Last Post: 01-05-2012, 11:59 AM
  3. array copy in class constructor.
    By Juukamen in forum New To Java
    Replies: 2
    Last Post: 10-29-2011, 01:07 AM
  4. copy constructor
    By shadow7 in forum New To Java
    Replies: 6
    Last Post: 12-29-2009, 07:56 PM
  5. Shallow Copy Test
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-17-2008, 12:04 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •