Answers for "benefits of encapsulation in c++"

C++
1

c++ encapsulation

#include <iostream>
using namespace std;

class Employee {
  private:
    // Private attribute
    int salary;

  public:
    // Setter
    void setSalary(int s) {
      salary = s;
    }
    // Getter
    int getSalary() {
      return salary;
    }
};

int main() {
  Employee myObj;
  myObj.setSalary(50000);
  cout << myObj.getSalary();
  return 0;
}
Posted by: Guest on October-13-2021

Code answers related to "benefits of encapsulation in c++"

Browse Popular Code Answers by Language