In C++, which access specifier makes a class member directly accessible only…

2010

In C++, which access specifier makes a class member directly accessible only within the class itself and to declared friends?

Answer: A. privateConceptAn access specifier controls which program contexts may directly name a class member. In C++, private, protected, and public provide progressively…

  1. A.

    private

  2. B.

    public

  3. C.

    protected

  4. D.

    derive

Attempted by 66 students.

Show answer & explanation

Correct answer: A

Concept

An access specifier controls which program contexts may directly name a class member.

In C++, private, protected, and public provide progressively broader direct-access domains; friendship grants explicitly declared exceptions.

Application

The stem asks for the specifier whose ordinary direct-access domain is confined to the class itself, while still accounting for declared friends. That definition corresponds to private.

Contrast

  • public allows access from any context where the object is accessible.

  • protected additionally allows access from derived classes under the language rules.

  • derive is not an access specifier in C++; derivation is the inheritance relationship between classes.

Cross-check

A member declared public would be accessible outside the class, and a protected member would also be accessible from derived classes. Only private has the restricted domain described in the stem.

Therefore, the required access specifier is private.

Explore the full course: Nta Ugc Net Paper 2

Loading lesson…