can anyone explain whether this is correct or else help me to write a proper answer plsss


answer.................


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.

Recommended Answers

All 5 Replies

Hi Precila. Your question makes absolutely no sense at all.:) When you say protected and private, what do you mean by that?

this is one of the questions i got 4 my assignment

so thougth of answering this by explaining what is protected and what is private mean

dont know whether my idea is correct cauz i hav no clue about this

>Private data members cannot be accessed outside the class.
Yes.

>When a class inherits a base class, all the data members except the private get inherited into it.
Private members are inherited, but not accessible from the child class.

>So if we want data members to be accessible to only derived classes
>and not privately or publicly accessible, then we can use protected.

While not incorrect, this answer is the kind of cookie cutter thing you'd get right out of a textbook. It shows knowledge, but not necessarily understanding.

A better answer would give a practical example for using protected, explain why it's preferred, then derive a more general guideline from the explanation. This covers all bases in that it shows you can think of a good situation where protected makes sense (understanding of the concept), defend the decision (understanding the pros and cons versus alternatives), and draw a logical conclusion (show creativity and independent thought).

tanx AndreRet and Narue you guy's were really helpfull tanx a lot 4 helping me to complete this

tanx a lot agian friends

It was a pleasure.:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.