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

Discussion Forum : Object Oriented Programming Using C++ - Section 1 (Q.No. 6)
6.
To expose a data member to the program, you must declare the data member in the _____ section of the class
common
exposed
public
unrestricted
user
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
3 comments Page 1 of 1.

Clim said:   6 years ago
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?

Nikhil bhandari said:   1 decade ago
Yes right all the public members are available to use outside the class body.

Hbhushan said:   1 decade ago
Ans: public - because memeber declare as public acess to whole program or within package.

Post your comments here:

Your comments will be displayed after verification.