• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Doubt on Mocktest

 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public class Mycircle {

public double radius;

public double diameter;



public void setRadius(double radius)

this.radius = radius;

this.diameter= radius * 2;

}



public double getRadius() {

return radius;

}

}







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.


Could you please tell me what is the answer?
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.



Option A is wrong because instance variables radius and diameter must be private not public for encapsulation.

Option B is wrong because there is public diameter variable can be set independently e.g diameter = 34;.

Option C is wrong because synchronization is nothing to do with encapsulation.

Option D is correct the reason public radius variable can be set radius = 3;
[ August 22, 2007: Message edited by: Ameen khan ]
 
Rototillers convert rich soil into dirt. Please note that this tiny ad is not a rototiller:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic