Friday, May 16, 2014

[Java] What are the benefits of data field encapsulation

Encapsulation in Java is a mechanism wrapping the variables and code acting on the data (methods) together as as single unit. The variables of a class will be hidden from other classes by using it, and can be accessed only through the methods of their current class. Benefits of data field encapsulation are :
  • The data fields of a class can be made read-only or write-only (for protecting data )
  • A class can have total control over what is stored in its fields (for easy to maintain the class.)
  • The user of a class don't know how the class stores its data. A class can change the data type of a field and users of the class do not need to change any of their code (for protecting data )
Remarks
Text provided above does not means is the model answer, and it's was posted here for an reference to somebody who interested the related knowledge only. if there is something incorrect, please leave a comment so that i can correct it or for others viewer to have an better reference, if you want know more about this topic and where is the question, concept or answer from, you can reference from information provided under the reference sub-title.

Reference:
1) Introduction to Java Programming, Y. Daniel Liang 9.21
2) http://www.tutorialspoint.com/java/java_encapsulation.htm

No comments :

Post a Comment