by Dinesh Thakur Category: Classes in C++

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.

                 Classes and its Object

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.

                        



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Related Articles