Explain why and when do we use protected instead of private

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.
What is a downcast? - C++
What is a downcast? - A downcast is a cast from a base class to a class derived from the base class...
What is a derived class? Define concrete derived class.
What is a derived class? Define concrete derived class - A derived class is a class that inherits the properties from its super class...
Numeric, character and boolean data types - C++
Numeric: This is a fundamental type provided by C++ language. Integers, Floating point types come under this...
Post your comment