aspose file tools*
The moose likes Beginning Java and the fly likes encapsulation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "encapsulation" Watch "encapsulation" New topic
Author

encapsulation

jaiser roney
Greenhorn

Joined: Jul 15, 2009
Posts: 16
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

Joined: Jul 15, 2009
Posts: 16
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.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36478
    
  16
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

Joined: Jul 15, 2009
Posts: 16
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
Sheriff

Joined: Oct 13, 2005
Posts: 36478
    
  16
Please start a new topic for your new question.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: encapsulation
 
Similar Threads
Encapsulation
immutable class
Difference between low coupling and encapsulation
Why does Sun exposes private methods through reflection
encapsulating static variables