What is difference between public and protected in C++ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 6

What is difference between public and protected in C++

Give answer plz

6th Nov 2019, 10:50 AM
Shaurya Barnwal
3 Answers
+ 4
Thanks for your opinions
30th Apr 2020, 8:31 AM
Shaurya Barnwal
+ 2
Specify for which language in the Relevant Tags section please 👍 (Edit) Sandeep Kumar Modi(Shaurya) Please edit your question and add 'C++ access-specifier public protected'. This clarifies the context of the question. These are taken directly from the C++ course: https://www.sololearn.com/learn/CPlusPlus/1714/?ref=app https://www.sololearn.com/learn/CPlusPlus/1908/?ref=app
6th Nov 2019, 11:06 AM
Ipang
+ 2
If we declare a member as public then we can access this member anywhere and even in other classes but class should be also public where you define your public method or variable. If you define protected member then we can access that variable anywhere in the current package but outside the package only child classes can be call. In current package we can access protected member by either parent reference or child reference. But outside only we can call protected members by giving them child reference.
6th Nov 2019, 11:35 AM
Maninder $ingh
Maninder $ingh - avatar