• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

copy constructor

 
Pritam Chatterjee
Ranch Hand
Posts: 38
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how and why to use copy constructors? Example
 
Campbell Ritchie
Sheriff
Pie
Posts: 48938
60
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To create an object identical to the original one.
To prevent the original being altered.Rather than returning the “real” account, you are returning a copy. That allows code to play with the account object without altering the original account object.
 
Pritam Chatterjee
Ranch Hand
Posts: 38
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks..
 
Campbell Ritchie
Sheriff
Pie
Posts: 48938
60
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You’re welcome
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic