From the course: Object-Oriented Programming with C++

Unlock this course with a free trial

Join today to access over 24,800 courses taught by industry experts.

Access specifiers

Access specifiers

- [Instructor] We've discussed how classes allow grouping related data and functions into a cohesive unit representing a specific entity in a software system. This concept is known as encapsulation, one of the fundamental ideas of object-oriented programming. The other pillar of object-oriented programming is data hiding. The idea is to only expose the essential features of a class and hide everything else. This is required to prevent exposing internal details that should not be used by callers and to protect the class from unwanted or accidental changes. If we allowed callers to freely change any member variable in our review class, they could set a six-star rating or a title longer than several thousand characters. We need to restrict direct access to the corresponding member variables to prevent such invalid entries. You can achieve data hiding using access specifiers. To hide the class member, use the private keyword. Private member variables and functions are only accessible from…

Contents