- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What are access modifiers in C++?
Data hiding is one of the important features of Object Oriented Programming which allows preventing the functions of a program to access directly the internal representation of a class type. The access restriction to the class members is specified by the labeled access modifiers: public, private, and protected sections within the class body.
The default access for members and classes is private
class Base { public: // public members go here protected: // protected members go here private: // private members go here };
A public member is accessible from anywhere outside the class but within a program. You can set and get the value of public variables without any member.
A private member variable or function cannot be accessed, or even viewed from outside the class. Only the class and friend functions can access private members.
A protected member variable or function is very similar to a private member but it provided one additional benefit that they can be accessed in child classes which are called derived classes.
- Related Articles
- What are access modifiers and non-access modifiers in Java?
- What are the differences between access modifiers and non-access modifiers in Java?
- Access Modifiers in C++
- Access Modifiers in C#
- What are different types of access modifiers available in C#?
- What are final, abstract, synchronized non-access modifiers in Java?
- Access Modifiers in Java
- What are private, public, default and protected access Java modifiers?
- Access and Non Access Modifiers in Java
- Non Access Modifiers in Java
- How many non-access modifiers are there in Java?
- What are sealed modifiers in C#?
- Types of access modifiers in Java?
- method overriding with access modifiers in Java
- java access modifiers with method overriding
