aspose file tools*
The moose likes Java in General and the fly likes Encapsulation in Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Encapsulation in Java" Watch "Encapsulation in Java" New topic
Author

Encapsulation in Java

Hs Raveendran
Greenhorn

Joined: Feb 05, 2010
Posts: 23

What is the best way define a Encapsulation in java.
Can you please give the good example for this
Pramod P Deore
Ranch Hand

Joined: Jul 15, 2008
Posts: 629

In Encapsulation we making the fields in a class private and providing access to the fields via public methods.



In this code you can not access variables name , id age from outside the class directly . To access them you have to go through getter and setter methods. And here if you want then you can add some logic which will protect your variables.


Life is easy because we write the source code.....
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19794
    
  20

Raveendran, I again ask you to SearchFirst. Like your previous question, this question has been asked and answered several times before.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Encapsulation in Java