Encapsulation in C++

  • Encapsulation is a process of wrapping of data and methods in a single unit. It is achieved in C++ language by class concept.

  • Combining of state (variables) and behavior (functions) in a single container (object) is known as encapsulation. In C++ language encapsulation can be achieve using class keyword, state represents declaration of variables on attributes and behavior represents operations in terms of method.

Benefits of Encapsulation:

  • The main advantage of using of encapsulation is to secure the data from other methods, when we make a data private then these data only use within the class, but these data not accessible outside the class.

  • Provides abstraction between an object and its clients.

  • Protects an object from unwanted access by clients.


class sum
 int a,b,c;

void add()
cout<<"Enter any two numbers: ";
cout<<"Sum: "<< c;
int main()
sum s;
return 0
Enter any two number: 
Sum: 12   

In above example all data and function are bind inside class sum.

Next topic is Abstraction


Training For College Campus

We offers college campus training for all streams like CS, IT, ECE, Mechanical, Civil etc. on different technologies like
C, C++, Data Structure, Core Java, Advance Java, Struts Framework, Hibernate, Python, Android, Big-Data, Ebedded & Robotics etc.

Please mail your requirement at info@prowessapps.in

Projects For Students

Students can contact us for their projects on different technologies Core Java, Advance Java, Android etc.

Students can mail requirement at info@prowessapps.in


(8AM to 10PM):

+91-8527238801 , +91-9451396824

© 2017, prowessapps.in, All rights reserved