Protected access modifier is similar to that of private access modifiers, the difference is that the class member declared as Protected are inaccessible outside the class but they can be accessed by any subclass(derived class) of that class.
id_protected is: 81
The class members declared as private can be accessed only by the functions inside the class. They are not allowed to be accessed directly by any object or function outside the class. Only the member functions or the friend functions are allowed to access the private data members of a class.
Radius is: 1.5 Area is: 7.065
Difference between Private and Protected
|The class members declared as private can be accessed only by the functions inside the class.||Protected access modifier is similar to that of private access modifiers.|
|Only the member functions or the friend functions are allowed to access the private data members of a class.||The class member declared as Protected are inaccessible outside the class but they can be accessed by any subclass(derived class) of that class.|
- Public vs Protected in C++ with Examples
- Can a constructor be private in C++ ?
- Private Destructor
- Can virtual functions be private in C++?
- How to call private method from another class in Java with help of Reflection API?
- Can we access private data members of a class without using a member or a friend function?
- Publicly inherit a base class but making some of public method as private
- Difference between C and C++
- Difference between while and do-while loop in C, C++, Java
- Difference between std::quick_exit and std::abort
- Difference between Definition and Declaration
- Difference between Inheritance and Polymorphism
- Difference between Abstraction and Encapsulation in C++
- Difference Between Constructor and Destructor in C++
- Difference between strncmp() and strcmp in C/C++
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.