It is mechanism to encapsulate or wrap up all the data members and member functions into a single entity that is class .It is used to prevent data from directly access. It is on eof the important feature of ObjectOriented that is helps in to data hiding.
Encapsulation can be achieved in two ways:
1. By using setter and getter methods.
2. Making all variables as private.
The variable price is set to private. This means that this can be accessed only by other members of the Car class, and not by any other part of your program. This is one way to achieve encapsulation in C++.
In the above program, we show how encapsulation works. We have a private member x which cannot be accessed from the main function. The only way to access it is by creating a object of class Exp.