aspose file tools*
The moose likes Beginning Java and the fly likes Public or Private ?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Public or Private ??" Watch "Public or Private ??" New topic
Author

Public or Private ??

arun mahajan
Ranch Hand

Joined: Dec 07, 2001
Posts: 305
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

Joined: Aug 26, 2001
Posts: 7610
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


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Anthony Villanueva
Ranch Hand

Joined: Mar 22, 2002
Posts: 1055
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Public or Private ??