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.|
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- 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?
- Publicly inherit a base class but making some of public method as private
- Can we access private data members of a class without using a member or a friend function?
- Difference between C and C++
- Difference between Python and C++
- Difference between Definition and Declaration
- Difference between while and do-while loop in C, C++, Java
- Difference Between Constructor and Destructor in C++
- Difference between Inheritance and Polymorphism
- Difference between Abstraction and Encapsulation in 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 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.