Explain why and when do we use protected instead of private

- Private data members cannot be accessed outside the class.

- When a class inherits a base class, all the data members except the private get inherited into it. So if we want data members to be accessible to only derived classes and not privately or publicly accessible, then we can use protected.


- Protected is similar to private.

- It makes class member inaccessible outside the class, but the members can be accessed by any subclass of that class.


No comments:

Post a Comment

The advantages of Outsourcing Web Development Services

In the present digital world, acquiring a solid web presence is essential for companies to flourish. A well designed site is much much more ...