Why the answer
should not be a valid answer? by doing that and then replacing sum with 200 it should have done the trick.Write another method setRadius2(int r) and set radiusB accordingly in this method.
The_Nick
Moderator: admin
should not be a valid answer? by doing that and then replacing sum with 200 it should have done the trick.Write another method setRadius2(int r) and set radiusB accordingly in this method.
Please post exact code that you want to write. Please go through the explanation once more. It is correct and explains the issue.kashyapa wrote:Could someone tell me, why the programmer cannot accomplish this goal by simply changing the sum to 200?
The explanation dos not make sense about it.
The point is to prevent users (and not the owner of the class) from messing with the behavior of the class and impact other users.Marthinus wrote:Even if the code was written with proper encapsulation principles in mind and you change the value of the private variable sum to 200 it would change the behaviour of the code and introduce a bug into legacy code.
The question does not mention that other classes access any of the fields. Under that circumstance I'd say this could be a correct answer.Make sum = 200 and make all fields (radiusA, radiusB, and sum) private.
Once the class is released, it cannot be known who uses what. public members become part of the public API and cannot be changed because that may break other people's code. That is the point of this question.fabbbb wrote:The question does not mention that other classes access any of the fields. Under that circumstance I'd say this could be a correct answer.Make sum = 200 and make all fields (radiusA, radiusB, and sum) private.
No, it is not ambiguous at all. "Breaking existing code" quite clearly implies that other existing code either fails compilation or fails to work as expected at runtime.igor.simecki wrote:"breaking existing code" statement is really a subjective matter and I really hope I don't get one of "these" questions.
I consider breaking existing code as in making whatever's using the method not compile, and there are such answers...
This particular matter is breaking the business logic and you assume that everybody's on the same boat with the change.
com.sun. package was always a subject for change and nobody called it code breaking.
why isn't setRadius2 an answer then? only new users would be aware of it and old users would have to rewrite their code... or use the old one, that's not "breaking their existing code".
It's a very ambiguous question if it's really just a matter of encapsulation.
Users browsing this forum: Bing [Bot], Google [Bot] and 52 guests