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

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

Prepare for the ultimate C++ challenge with our comprehensive quiz based on 'Thinking in C++'. Test your knowledge with engaging questions and receive instant feedback. Perfect for both beginners and experienced C++ programmers looking to sharpen their skills!

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 do you need to do to allow a derived class to use the members of its base class?

  1. Declare them as public in the derived class

  2. Inherit them using the 'protected' keyword

  3. Inherit them using the 'public' keyword

  4. Copy them to the derived class

The correct answer is: Inherit them using the 'public' keyword

In order for a derived class to use the members of its base class, the 'public' keyword should be used to inherit those members. This allows for the derived class to have access to the public members of the base class without explicitly declaring them again. Option A is incorrect because public members in the base class can already be accessed by derived classes without needing to declare them again. Option B is incorrect because the 'protected' keyword only allows for access by the base class and its derived classes, but not by other classes in the program. Option D is incorrect because copying the members to the derived class would create duplicate code and defeat the purpose of inheritance.