0

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.

Edited by precila: adding more info

3
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by AndreRet
0

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

0

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

0

>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).

0

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

tanx a lot agian friends

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.