In C++, all members of a class are ______ by default.

2023

In C++, all members of a class are ______ by default.

Answer: B. privateIn C++, when a class is defined, the default access specifier for its members (data members and member functions) is private. This means that unless…

  1. A.

    public

  2. B.

    private

  3. C.

    protected

  4. D.

    More than one of the above

  5. E.

    None of the above

Attempted by 871 students.

Show answer & explanation

Correct answer: B

In C++, when a class is defined, the default access specifier for its members (data members and member functions) is private. This means that unless explicitly specified otherwise, all members of a class are private by default. This behavior ensures encapsulation, a key principle of object-oriented programming.

Explore the full course: Bpsc

Loading lesson…