Computer Science : Information Hiding

Study concepts, example questions & explanations for Computer Science

varsity tutors app store varsity tutors android store

Example Questions

Example Question #73 : Program Implementation

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

public

virtual

private

friend

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

Incompatible Browser

Please upgrade or download one of the following browsers to use Instant Tutoring: