🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to C++ Notes
Topic #97

Access Specifiers


Access Specifiers

You learned from the Access Specifiers chapter that there are three specifiers available in C++.

Until now, we have only used public (members of a class are accessible from outside the class) and private (members can only be accessed within the class).

The third specifier, protected, is similar to private, but it can also be accessed in the inherited class:

Example

// Base class
class
Employee {
  protected: // Protected access specifier

int salary;
};

// Derived class
class Programmer: public Employee {

public:
    int bonus;
    void
setSalary(int s) {
      salary = s;

}
    int getSalary() {

return salary;
    }
};

int main() {

Programmer myObj;
  myObj.setSalary(50000);
  myObj.bonus =
15000;
  cout <<
"Salary: " << myObj.getSalary() << "\n";
  cout << "Bonus: " <<
myObj.bonus << "\n";
  return 0;
}

Want to go beyond the notes?

Join CodingNow 2.0's C++ course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

Access Specifiers – FAQs

Quick answers about learning Access Specifiers in C++.

This free note from CodingNow 2.0 explains Access Specifiers in C++ — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every C++ topic on CodingNow 2.0, including Access Specifiers, is 100% free with no signup required.
With focused practice, most students grasp Access Specifiers in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now