Data encapsulation

Data encapsulation/ data hiding is an important feature of object oriented programming. The mechanism of hiding data is to put them in a class and make them private. The data is now hidden and safe from any accidental manipulations, i.e. no function (from outside the class) can change the member data. Actually there are two things you can hide: implementation of functions (to the user it doesn't matter as to how you've implemented a particular function) and data. In procedural programming it is possible to only hide the implementation details but you cannot hide/ protect data. OOP lets you achieve this. A simple example is the case of the ‘car' (Explained in Data Abstraction, go through the next question). We don't want the user to directly access ‘speed' and modify it. By making ‘speed' private, we prevent the user from doing this.

Next Recommended Reading What Is An Encapsulation