This week's book giveaways are in the Scala and Android forums.
We're giving away four copies each of Machine Learning Systems: Designs that scale and Xamarin in Action: Creating native cross-platform mobile apps and have the authors on-line!
See this thread and this one for details.
Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

DOUBT REGARDING OBJECT REFERENCES  RSS feed

 
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
//--------------------------
class1 object1 = new class1();
class1 object2;

object2=object1;
//------------------------------


now in the code given above, object1 and object2 are acting as references to the same object. so whatever value that you change in object1 will be reflected in object2 also.

now how to prevent this? or how to create object2 as an exact copy of object1 but an autonomous object?

one way is to copy all the member data individually from object1 to object2. Is there any other way?

ARUL JOSE.
 
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And please don't shout at us...
 
I didn't like the taste of tongue and it didn't like the taste of me. I will now try this tiny ad:
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!