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

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

Test your C++ skills with our quiz based on Bruce Eckel's 'Thinking in C++'. Dive into object-oriented programming, advanced topics, and fundamentals. Perfect for learners and experts alike. Assess your knowledge and become a C++ master!

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.


What must be added before a base class in an inheritance declaration to keep its public members public in the derived class?

  1. public

  2. private

  3. protected

  4. internal

The correct answer is: public

In object-oriented programming, inheritance allows for the creation of new classes that inherit traits and behaviors from a parent or base class. When a base class's public members need to be accessible in a derived class, the keyword "public" must be added before the base class in the inheritance declaration. This makes sure that the public members remain accessible in the derived class. The other options, "private", "protected", and "internal", all restrict access to the public members and thus would not maintain their public accessibility in the derived class.