1. Home
  2. Computer Science MCQs
  3. C++ and Object-Oriented Programming
  4. What is the default access level for members of a class…

Added 30 Nov -0001

What is the default access level for members of a class declared with the class keyword in C++?

  1. private, unlike struct members which default to public Correct answer
  2. public, the same as members of a struct
  3. protected, so only derived classes and friends may access them
  4. It depends on whether a constructor is declared

Correct answer

A. private, unlike struct members which default to public

14 views

MCQSEXAM

Explanation

In C++ the only difference between class and struct is the default access and default inheritance: class members are private and class inheritance is private, while struct members and inheritance are public. Many codebases therefore use struct for plain data aggregates and class for types with invariants. Forgetting the difference is a frequent cause of "member is inaccessible" errors.

Reference

Asked in: NTS, PPSC IT, Campus Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is A? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More C++ and Object-Oriented Programming MCQs

Practise all C++ and Object-Oriented Programming MCQs

Similar MCQs