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.|
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Public vs Protected in C++ with Examples
- Protected keyword in Java with examples
- Private Destructor
- Can a constructor be private in C++ ?
- 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 Python and C++
- Difference Between Constructor and Destructor in C++
- Difference between Inline and Macro in C++
- Similarities and Difference between Java and C++
- Difference between Abstraction and Encapsulation in C++
- Difference between Inheritance and Polymorphism
- Difference between std::quick_exit and std::abort
- Difference between Definition and Declaration
- Difference between strncmp() and strcmp in C/C++
- Difference between namespace and class
- Difference between while and do-while loop in C, C++, Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.