aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes access modifier doesn't affect encapsulation? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "access modifier doesn Watch "access modifier doesn New topic

access modifier doesn't affect encapsulation?

Stephen Huey
Ranch Hand

Joined: Jul 15, 2003
Posts: 618
The MasterExam software with Bert & Kathy's book has an explanation for a question that says that the "access modifier does not affect encapsulation". My copy of the software does not allow me to go back and find that question after time has expired, and my frantic in-exam notes with a question mark about this topic weren't extensive enough for me to know exactly what the situation was, but I suppose I can ask about when you can say there is good encapsulation in general since I'm a little hazy on this. I understand that public setters/getters with private members makes for tight encapsulation, and that an example of bad (or loose?) encapsulation would be public instance member variables, but in case the exam tests me on this, I'm trying to figure out how to accurately describe the level of encapsulation when member vars and methods have other combinations with protected/default and such. Any concise/memorable explanation would be greatly appreciated!
Paul Anilprem
Enthuware Software Support
Ranch Hand

Joined: Sep 23, 2000
Posts: 3413
The purpose of encapsulation is to keep inner workings of the component invisible (read private) to the outside world while providing access to the properties using acessor methods (read setters and getters). So, it is imperative that the members field is private and the accessor methods are public.
In this sense, access modifier does affect encapsulation. If you have a public member variable with private accessor methods( ), then it is not encapsulation.

Enthuware - Best Mock Exams and Questions for Oracle/Sun Java Certifications
Quality Guaranteed - Pass or Full Refund!
Stephen Huey
Ranch Hand

Joined: Jul 15, 2003
Posts: 618
Yeah, but I know the question had something to do with how you describe the level of encapsulation when you're dealing with protected/default access, and I understand what level of access protected/default gives, but I'm just wondering if they're going to throw a tricky question at me about how you describe the encapsulation (like, does a protected member var or method show good encapsulation?).
I agree. Here's the link:
subject: access modifier doesn't affect encapsulation?