Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Public or Private ??

 
arun mahajan
Ranch Hand
Posts: 305
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Will making public and private objects make a differance on Memory management? or this only useful in encapsulating the objects?
regards,
Arun
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Access modifiers are only useful for encapsulation purposes. A variable that is declared private and points to some object doesn't want the object it is referencing being garbage-collected... Does it make sense?
Only unreferenced objects may be garbage-collected.
The following threads contains some pointers to garbage-collection and how the latter works:
SCJP Forum: Good resources on Garbage Collection
 
Anthony Villanueva
Ranch Hand
Posts: 1055
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Ideally, the data representation of a class is nobody else's business but its own. That way, a client class wouldn't be tempted to directly make use of the data representation. If the data representation is changed in any way (pretty common thing really) the implementing methods of client classes will be unaffected. So make your instance and static variables (and your internal helper methods as well) private unless you really really must.
-anthony
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic