170k views
2 votes
Consider this class:

class Foo {
public:
int id;
int ego;
private:
int superego;
};
What access does ego have?

a) Public
b) Private
c) Protected

1 Answer

3 votes

Final answer:

The member 'ego' in class Foo has public access, allowing it to be accessed from anywhere in the program where an object of the class is available.

Step-by-step explanation:

In the given class Foo, the member 'ego' has public access. This means that it can be accessed from anywhere in the program where an object of the class Foo is available. Unlike private members, which are only accessible within the class itself or through friend classes and functions, public members are accessible from outside the class. In contrast, the member 'superego' is marked as private, meaning it cannot be accessed directly from outside the class.

Access specifiers in classes, such as public, private, and protected, determine the visibility and accessibility of the class members (variables and functions). In this case, 'ego' being public means that any part of the code that has an object of the class Foo can directly interact with the 'ego' member.

User Makram Saleh
by
7.8k points