This week's book giveaway is in the Artificial Intelligence forum.
We're giving away four copies of Pragmatic AI and have Noah Gift on-line!
See this thread for details.
Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

encapsulation-doubt  RSS feed

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Given the following program:

1.public class MyCircle
2.{
3.public double radius;
4.public double diameter;
5.
6.public void setRadius(double radius)
7.{
8.this.radius=radius;
9.this.diameter=radius*2;
10.}
11.public double getRadius()
12.{
13.return radius;
14.}
15.}

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?
 
Ranch Hand
Posts: 286
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you have totally reasons...
d is right

arno
[ April 09, 2006: Message edited by: Arno Reper ]
 
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes,
option 'd' is correct.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!