wood burning stoves*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Encapsulation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Encapsulation" Watch "Encapsulation" New topic
Author

Encapsulation

Nilesh Parikh
Ranch Hand

Joined: Mar 14, 2000
Posts: 52
Which is the advantage of encapsulation?
A.Only public methods are needed.
B.No exceptions need to be thrown from any method.
C.Making the class final causes no consequential changes to other code.
D.It changes the implementation without changing the interface and causes no consequential changes to other code.
E.It changes the interface without changing the implementation and causes no consequential changes to other code.

I think the correct answer is c)
Any comments
Alkesh
veena devi
Greenhorn

Joined: Aug 25, 2003
Posts: 18
Correct answer is d.
D.It changes the implementation without changing the interface and causes no consequential changes to other code
because encapsulation is meant for hiding your implementation
(code inside your method).your classes are used only through the interfaces(methods name) you provide.so you can change the code inside your method without actually affecting the interface

making a class final is related to another feature of oops called inheritance
maha anna
Ranch Hand

Joined: Jan 31, 2000
Posts: 1467
Alkesh,
A very good encapsulation implies keeping all states(member vars) as private, and all methods as public. Messages are passed between objects through their methods. Since all member vars are kept private (encapsulated) within the class itself, all other objects can talk to this object only through their public methods. Outsider classe objects CAN NOT change the member vars. So when you want to change the implementation of a method you can always do it without affecting the other parts of the program which uses this class. Which means you can easily change the implementaion at any time without affecting the public interface methods. Outsider classes don't even know that the implemantaion has been changed in the class which uses tight encapluation because outsider classes were never allowed to access the member vars. So changing the implementation makes no difference as far as outsider classes are concerned.
This info can be useful to answer the above qstn. You can also easily say which choices in the above qstn are related to encaptulation.
Please confirm us whether you are convinced with your answers and the reasoning for the same.
regds
maha anna
[This message has been edited by maha anna (edited March 25, 2000).]
Nilesh Parikh
Ranch Hand

Joined: Mar 14, 2000
Posts: 52
hi Anna,
I totally agree with you now.
It changes the implementation without changing the interface and causes no consequential changes to other code.
This is the right option
Alkesh
maha anna
Ranch Hand

Joined: Jan 31, 2000
Posts: 1467
Yes. Your ans is correct and so quick also.
regds
maha anna
Rolf Weasel
Ranch Hand

Joined: Feb 26, 2000
Posts: 82
This question is one of the sample questions at the sun site and i must say it worries me a bit. The grammer is atrocious!
D.It changes the implementation without changing the interface and causes no consequential changes to other code.
Sun says they got all sorts of language experts going thru all questions in the real exam. One would think the few sample questions would at least make sense.
[This message has been edited by Rolf Weasel (edited March 25, 2000).]


May the Moose be with you.
maha anna
Ranch Hand

Joined: Jan 31, 2000
Posts: 1467
Rolf,
Which part of the answer worries you and why? Is that the word interface ? If so, if you read the qstn in this particular context it makes sence.( for Maha atleast. . )
regds
maha anna
Rolf Weasel
Ranch Hand

Joined: Feb 26, 2000
Posts: 82
'It' changes the implementation without changing the interface and causes no consequential changes to other code. Encapsulation does not change implementation, a programmer does! and changing the interface can't `cause consequential changes to the other code', it can only `require consequential changes to the other code'!
if there's questions worded like this on the actual exam, gawd help us!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Encapsulation
 
Similar Threads
Please help me !!!!!answers for sun sample questions
sun's sample questions.
Encapsulation...
sample sun test
Am i correct?