Examveda

Which access specifier allows members of a class to be accessed only by member functions of the same class and its derived classes in C++?

A. protected

B. public

C. private

D. friend

Answer: Option A

Solution (By Examveda Team)

Access specifiers in C++ determine the visibility and accessibility of class members.

The protected access specifier allows members of a class to be accessed by:

1. Member functions of the same class

2. Member functions of its derived (child) classes

This makes protected different from private, which restricts access only to the class itself, and from public, which allows access from anywhere.

Now let’s see why the other options are incorrect:

Option B: public — Members are accessible from anywhere in the program, which is more permissive than required by the question.

Option C: private — Members are accessible only within the same class, not by derived classes, so this is too restrictive.

Option D: friendfriend is not an access specifier; it is a keyword used to allow a specific external function or class to access private or protected members of another class. It doesn’t define a general access level.

Conclusion: The protected access specifier is the one that allows class members to be accessed within the same class and its derived classes.

Hence, the correct answer is Option A: protected.

Join The Discussion

Comments (1)

  1. KRISHNA MOHAN
    KRISHNA MOHAN:
    6 months ago

    the correct answer of this question will be protected.
    protected means same class and its derived class.

Related Questions on Classes and Objects in C plus plus