We know in java, encapsulation is a process of wrapping up of code data together into a single unit or hiding the data. Can anybody let me know from whom we are hiding the data?
-
4Possible duplicate of [Encapsulation vs Data Hiding - Java](https://stackoverflow.com/questions/12013448/encapsulation-vs-data-hiding-java) – Gino Mempin May 10 '19 at 09:20
2 Answers
You are "hiding" data from users of your object that should be able to use it without needing to know about its internals.
The main reason for this is to allow you to later change these internals without breaking the code that calls into your object.
This is a technique to improve software maintainability.
Common misconception: It should definitely not be seen as a security measure (in the sense that it protects sensitive data from malicious actors that should not be allowed to gain access to it -- encapsulation does no such thing).

- 257,207
- 101
- 511
- 656
-
So, basically if whatever code i have written in some Application is later on used by the other developer for some enhancement, it should not break the code? – Shantha Kumar V May 21 '19 at 04:58
-
That is the idea, yes. As long the developer sticks to the public interface of your code, you can change the implementation details without breaking their applications (as long as the new implementation still does what the interface said it should do). – Thilo May 21 '19 at 07:18
Data hiding is a software development technique specifically used in object-oriented programming (OOP) to hide internal object details (data members). Data hiding ensures exclusive data access to class members and protects object integrity by preventing unintended or intended changes.
Data hiding also reduces system complexity for increased robustness by limiting interdependencies between software components.
That's why Data hiding is also known as data encapsulation or information hiding.

- 51
- 5