What is the significance of access specifiers in a class




















Popular Course in this category. Course Price View Course. Free Software Development Course. Login details for this Free course will be emailed to you. Email ID. Contact No. W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use , cookie and privacy policy.

Copyright by Refsnes Data. All Rights Reserved. In the Person class from the previous topic we used only public access specifiers for all data members:. Public class members and functions can be used from outside of a class by any function or other classes. You can access public data members or function directly by using dot operator. So in above program, the derived class cannot access the member x which is private in the base class, however, derive class has access to the protected and public members of the base class.

So the. Hence the function showdata in derived class can access the public and protected member of the base class. If protected access specifier is used while deriving class then the public and protected data members of the base class becomes the protected member of the derived class and private member of the base class are inaccessible.

In this case, the members of the base class can be used only within the derived class as protected members except for the private members.



0コメント

  • 1000 / 1000