encapsulation is code example
Example 1: encapsulation programming
In object-oriented programming, encapsulation refers to the bundling
of data with the methods that operate on that data, or the restricting
of direct access to some of an object's components
Example 2: oop encapsulation example
#include<iostream>
using namespace std;
class ExampleEncap{
private:
int num;
char ch;
public:
int getNum() const {
return num;
}
char getCh() const {
return ch;
}
void setNum(int num) {
this->num = num;
}
void setCh(char ch) {
this->ch = ch;
}
};
int main(){
ExampleEncap obj;
obj.setNum(100);
obj.setCh('A');
cout<<obj.getNum()<<endl;
cout<<obj.getCh()<<endl;
return 0;
}
Example 3: Encapsulation
In object-oriented programming, encapsulation refers to the bundling of data with the methods that operate on that data, or the restricting of direct access to some of an object's components