Computer Science : Information Hiding

Study concepts, example questions & explanations for Computer Science

varsity tutors app store varsity tutors android store

Example Questions

Example Question #231 : Computer Science

Class Person {

int height;

float weight;

 

public:

int getHeight();

void setHeight(int);

float getWeight();

void setWeight(float);

};

What is the access level of height and weight?

Possible Answers:

protected

friend

private

public

virtual

Correct answer:

private

Explanation:

Until an access specifier is given, all class members are implicitly private. All members defined after an access specifier is used will will have that access level until another access specifier is explicitly invoked. Since no access specifier was used, weight and height are automatically private. 

Note that virtual is not an access keyword.

Learning Tools by Varsity Tutors