I agree with David, 3 and 4.
But I am more convinced than David that 4 is correct. Because I read "greater security" as he first read it, not as security from access by unauthorized users.
I think security in the ideas of the makers of the exam stands for program safety - in respect of exceptions thrown, etc.
A encapsulated int variable e.g. cannot be set to sub zero accidently, if the setter doesn't provide negative values. This kind of things.
3 is also correct as David said. Because the interface (API, do not mix up with interface {}
) shows only how the class can be used, and not how the class actually performs its tricks.
David also wrote:
I would hate to find a question like that on the exam!
I'm afraid the sentence should start: "I
will hate ..."
Andi:
#3 doesnt sound like a benefit of tight encapsulation to me, rather it is a way of achieving tight encapsulation. Quite different really!
Hm... First you achieve it, and then you have the benefits?
If this was from a mock exam, was the correct answer provided?
If only one answer was allowed, I'd favourite 4 over 3
Yours,
Bu.