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

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

Study for the C++ exam based on 'Thinking in C++'. Engage with challenging quiz questions designed to boost your understanding and proficiency in C++. Get prepared to master C++ programming concepts through an interactive and informative quiz experience!

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 done to extend the program with a new instrument class that works with the 'tune()' function?

  1. Overload 'tune()' for the new class

  2. Inherit from 'Instrument' and optionally override 'play()'

  3. Rewrite 'tune()' to recognize the new class

  4. None of the above

The correct answer is: Inherit from 'Instrument' and optionally override 'play()'

In this case, the correct answer is B because inheriting from the 'Instrument' class would allow the new instrument class to have access to the 'tune()' function. This option also allows for the option to override the 'play()' function if necessary. Option A, overloading the 'tune()' function, is not necessary as the original function can be used for the new instrument class. Rewriting the 'tune()' function as in option C would not be efficient as it would involve duplicating code and could potentially cause conflicts with the existing code. Lastly, option D, none of the above, is not the correct answer as one of the provided options is indeed the correct solution for extending the program.