Encapsulation in C++
Encapsulation is one of the object oriented programming concepts which binds the data and functions together. It makes the whole thing into a single unit. Generally, this single unit is considered as a class . Encapsulation is achieved by using access specifiers as follows.. ‘ public ’: member variables can be accessible for anywhere in the class. ‘ private ’: this type of variable accessed by current class only. ‘ protected ’: it can be accessible by class and derived class. Let us create a c++ program to display the student details. C++ program: Here, ‘ Student ’ is the class. It has set() method to display the data. The get() method gets the data. Using the object, we call the set() and get() function. Code: #include <iostream> using namespace std; class Student { private: string s_name; string s_id; int s_age; public: // Constructor Student(string s_name,string s_id ,int s_age) { ...