Computer Science - Object Oriented Programming Using C++ - Discussion

6. 

To expose a data member to the program, you must declare the data member in the _____ section of the class

[A]. common
[B]. exposed
[C]. public
[D]. unrestricted
[E]. user

Answer: Option C

Explanation:

No answer description available for this question.

Hbhushan said: (Aug 14, 2011)  
Ans: public - because memeber declare as public acess to whole program or within package.

Nikhil Bhandari said: (Jun 6, 2012)  
Yes right all the public members are available to use outside the class body.

Clim said: (Oct 18, 2019)  
What about this?

class foo{
private:
int bar;

public:
foo(int b): bar(b){}
int getBar(){ return this->bar;}
void setBar(int b){ this->bar = b;}
};

int main(){
foo f(15);
std::cout << f.getBar();
}

Did I just not expose a private data member to the program?

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.