From 83bdf460c545810dbb2078b6d013e1982d53e00a Mon Sep 17 00:00:00 2001 From: Arbaaz Shaikh Date: Sun, 29 Oct 2023 22:58:01 +0530 Subject: [PATCH] Create Encapsulation.cpp This is the code for accessing private class in C++ where Encapsulation method is used which also the part OOPs. --- Encapsulation.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Encapsulation.cpp diff --git a/Encapsulation.cpp b/Encapsulation.cpp new file mode 100644 index 0000000..e85ac12 --- /dev/null +++ b/Encapsulation.cpp @@ -0,0 +1,22 @@ +#include +using namespace std; + +class Employee { + private: + int salary; + + public: + void setSalary(int s) { + salary = s; + } + int getSalary() { + return salary; + } +}; + +int main() { + Employee myObj; + myObj.setSalary(50000); + cout << myObj.getSalary(); + return 0; +}