• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

shallow copy and deep copy

 
Ranch Hand
Posts: 266
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I read this statement regarding

Shallow copy: If a shallow copy is performed on obj-1 then it is copied but its contained objects
are not.

I did not understand this statememt , how can one object ahve other objects within it ?

Can i say an array of arrays is an example where we have objects within an object ?
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's basically another way of saying that there is HAS-A relation between two classes

Suppose we have following two classes :
class A{
private int a,b,c;
}


public class B{
private int bla1,bla2,bla3;
private A a;
}


now If we create an object of B, and then try shallow copying, then bla1,bla2,bla3 would be copied , but not the content referenced by a
 
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


beaten to the punch
 
Sheriff
Posts: 22822
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

jose chiramal wrote:I did not understand this statememt , how can one object ahve other objects within it ?


Arrays, Lists, Collections, Maps, but also non-collection classes. The values of instance fields are also objects contained by an object:
 
What's wrong? Where are you going? Stop! Read this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic