posted 19 years ago
Answer: D.
A. Both instance variables are public, so the class is definitely not encapsulated.
B. Because setRadius() is not synchronized, if two threads simultaneously invoke the method with different values, it is possible that the diameter ends up being a value different from that of 2 * this.radius.
In addition, since the class isn't encapsulated, you could clearly set the instance variables to anything you'd like.
C. setRadius should be synchronized, but it doesn't have anything to do with encapsulation.
D. Since the class isn't encapsulated, you could do this by setting the instance variable directly. Using the setRadius method would affect the diameter so that wouldn't work.
Nathaniel Stodard<br />SCJP, SCJD, SCWCD, SCBCD, SCDJWS, ICAD, ICSD, ICED