Encapsulation.

Q16. What is encapsulation? Why is data considered safe if encapsulated?

Ans. The wrapping up of data and operations/functions (that operate on the data) into a single unit (called class) is known as Encapsulation.

The only way to access the data is provided by the functions (that are combined along with the data). These functions are called member functions in C++. The data cannot be accessed directly. If you want to read a data item in an object (an instance of the class), you call a member function in the object. It will read the item and return the value to you. You can’t access the data directly. The data is hidden, so it is safe from accidental alteration.

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: