Which statement is true? A. The Mycircle class is fully encapsulated. B. The diameter of a given MyCircle is guaranteed to be twice its radius. C. Lines 6 and 7 should be in a synchronized block to ensure encapsulation. D. The radius of a MyCircle object can be set without affecting its diameter.
I think the right answer is D, am I right? thanks advance! [ November 24, 2006: Message edited by: Barry Gaunt ]
I am convinced that the answer is B. A is false because the class is not encapsulated as the members and the class are left public. C putting those two lines in a block won't encapsulate, I don't see how it would. D, once the radius is set, the diameter is obvious from the formula.
But still, this option isn't correct, because, this doesn't seem to be related with encapsulation.
Looking at this from another perspective, if the method setRadius() isn't synchronized & is accessed by multiple threads at the same time, it will result in disaster. The radius & diameter variables may get inconsistent/incorrect values due to this. Will this break/affect the encapsulation then? Anyone on this...
D. The radius of a MyCircle object can be set without affecting its diameter.
Yes, indeed. Both instance variables are public and therefore, can be changed in any manner whatsoever.
A & B are incorrect & D is correct, undoubtedly. I am unsure about option C.
Best regards, Abdul Rehman. [ November 24, 2006: Message edited by: Abdul Rehman ]