
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Difference between private, public, and protected inheritance 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.
Example Code
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 Questions & Answers
- Difference between private, public, and protected modifiers in C++
- Difference Between Private and Protected in C++
- What are the differences between public, protected and private access specifiers in C#?
- Difference between Private and Public IP addresses
- Difference between Private Key and Public Key
- What are private, public, default and protected access Java modifiers?
- Private and Protected Members in C++
- Can we declare an abstract method, private, protected, public or default in java?
- Difference Between Inheritance and Polymorphism
- Difference Between Single and Multiple Inheritance
- Difference between inheritance and composition in Java
- What is difference between internal and private modifiers in C#?
- What are public and private variables in Python class?
- Difference Between Virtual Private Network (VPN) and Proxy
- What is the difference between public, static and void keywords in C#?