This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Dan's question, OO programming Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Dan Watch "Dan New topic

Dan's question, OO programming

David Jones

Joined: Dec 26, 2003
Posts: 27
A class can not be called "tightly encapsulated" unless which of the following is true?
a. The class is declared final.
b. All local variables are declared private.
c. All method parameters are declared final.
d. No method returns a reference to any object that is referenced by an internal data member.
e. None of the above
Answer : E. THe explanation is "However, the methods of a tightly encapsulated class may return a reference to an immutable object or a reference to a copy or clone of an internal object.". I don't quite understand to this sentence. What is "a reference to a copy or clone of an internal object"? And reference to an immutable object, does it mean to a String object?
Dan Chisholm
Ranch Hand

Joined: Jul 02, 2002
Posts: 1865
The following code demonstrates what can happen if you allow an object to return a reference to an internal object that is not immutable.

The program output is as follows.
That problem can be avoided if the getIt method returns a reference to a copy of the StringBuffer instance rather than a reference to the same StringBuffer instance that is a member of class A.

Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="" target="_blank" rel="nofollow">Try my mock exam.</a>
David Jones

Joined: Dec 26, 2003
Posts: 27
Hi Dan,
Thanks for the reply. I am now understand ...
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: Dan's question, OO programming
jQuery in Action, 3rd edition