+ 6
What is difference between public and protected in C++
Give answer plz
3 Answers
+ 4
Thanks for your opinions
+ 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
+ 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.