Mastering C++: A Comprehensive Quiz Based on 'Thinking in C++'

Disable ads (and more) with a membership for a one time $2.99 payment

Master C++ with our comprehensive quiz based on 'Thinking in C++'. Test your knowledge through flashcards and multiple-choice questions to enhance your understanding of C++. Prepare effectively for your exam!

Each practice test/flash card set has 50 randomly selected questions from a bank of over 500. You'll get a new set of questions each time!

Practice this question and more.


Which access specifier would you use to hide data members from the user of the class while allowing derived classes to access them?

  1. Public

  2. Private

  3. Protected

  4. Friend

The correct answer is: Protected

Protected access specifier is used to hide data members from the users of the class, while allowing derived classes to access them. Public access would allow anyone to access the data members, private access would only allow the class itself to access the data members, and friend access would only allow designated friend classes to access the data members. Therefore, protected is the most appropriate access specifier for this scenario.