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

Question: 1 / 565

What must be done to extend the program with a new instrument class that works with the 'tune()' function?

Overload 'tune()' for the new class

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.

Get further explanation with Examzify DeepDiveBeta

Rewrite 'tune()' to recognize the new class

None of the above

Next Question

Report this question

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy