This week's book giveaway is in the OCAJP forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes encapsulation-doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide 1Z0-808 this week in the OCAJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "encapsulation-doubt" Watch "encapsulation-doubt" New topic


Vidya Ramachandran

Joined: Nov 04, 2005
Posts: 24
Given the following program:

1.public class MyCircle
3.public double radius;
4.public double diameter;
6.public void setRadius(double radius)
11.public double getRadius()
13.return radius;

Which statement is true?

a) MyCircle is fully encapsulated
b) The diameter is guarenteed to be twice the radius
c)Lines 8 and 9 should be in a synchronized block to ensure encapsulation
d)The radius of a Mycircle object can be set without affecting its diameter

According to the mock exam, the Answer is b.

But isnt b wrong. radius being a public variable can be modified by anyone. So how is this behaviour guaranteed. I feel d shud be the answer.. Any comments?
Arno Reper
Ranch Hand

Joined: Mar 14, 2006
Posts: 286
you have totally reasons...
d is right

[ April 09, 2006: Message edited by: Arno Reper ]

The man who makes no mistakes does not usually make anything<br /> <br />>>> SCJP 5.0 >> SCJD B&S <<< In progress
Naresh Gunda
Ranch Hand

Joined: Oct 15, 2005
Posts: 163
option 'd' is correct.
I agree. Here's the link:
subject: encapsulation-doubt