Help coderanch get a
new server
by contributing to the fundraiser
  • 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

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

while going through basics of java i come around the below points for encapsulation. Can any one explain the points with example

1)An encapsulated, public class promotes re-use.

2)An encapsulated class allows a programmer to implementation without affecting outside code.

Thanks in advance.
 
jaiser roney
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
second point is missing a word

appology for the inconvenience

it as
2)An encapsulated class allows a programmer to change an
implementation without affecting outside code.
 
Marshal
Posts: 79523
379
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because the two Kettle classes are encapsulated users of the class cannot tell whether the temperature is maintained by the Kettle or a Water object. And they don't care. They know that calling boil() on a Kettle instance will set its temperature to 100°C and calling empty() will set the amount of water to 0. That's all they need to know.
 
jaiser roney
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Campbell,

I have one more query regarding Threads

How can we make a method thread-safe (but in terminology we are talking about classes as thread safe) by declaring it as static, i know about synchronized concept but is it possible to make thread safe with only static key word.
 
Campbell Ritchie
Marshal
Posts: 79523
379
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please start a new topic for your new question.
 
Honk if you love justice! And honk twice for tiny ads!
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic