• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Encapsulation-- Dan's Mock Exam

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

I know its not code...but i put it as such so that it is more readable
Answer: e. None of the Above
If a class A has a method that returns a reference to an internal, mutable object; then external code can use the reference to modify the internal state of class A. Therefore, class A can not be considered tightly encapsulated. However, the methods of a tightly encapsulated class may return a reference to an immutable object or a reference to a copy or clone of an internal object.

I didnt quite understand the explanation.Can someone tell me what is the difference between a reference to an internal data member and a reference to a clone of an internal object. Is clone the key word here?
 
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Murtuza,

A tightly encapsulated class controls access to its internal data members. If a class named A returns a reference to a mutable internal data member, then the reference can be used to change the internal state of class A. If class A returns a reference to a copy or clone of an internal data member, then the internal state of the copy or clone can be changed; but that copy or clone is not part of the internal state of class A.
reply
    Bookmark Topic Watch Topic
  • New Topic