Encapsulation is the technique of binding or keeping together the data and the functions (that operate on them) in a single unit called a class. Encapsulation is the way to implement data abstraction. A well-encapsulated object acts as a 'black box' for other parts of the program. That is, it provides services to the external functions or other objects that interact with it. However, these external functions or the objects do not need to know its internal details. For example, the data p_code, p_name, p_price and qty_in_hand and the functions display-product() and check_qty are encapsulated in a class Product.
The hidden data of a class cannot be accessed directly by the outside world. However, the member functions of the class act as a medium to access the hidden data. This process of preventing the data from the direct access by the external functions is called data hiding. Note that the values of the hidden data members cannot be passed to the outside world unless the functions are written to pass that information outside the class.