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 is the result of calling 'play()' on a 'Brass' object when 'play()' is made virtual?

  1. It calls the most closely matched overridden function in the hierarchy

  2. It defaults to the base class implementation

  3. It generates a runtime error

  4. None of the above

The correct answer is: It calls the most closely matched overridden function in the hierarchy

When a virtual function is called from a derived class object, it will call the most closely matched overridden function in the hierarchy. This means that if a 'Brass' object has a 'play()' function defined, it will call that function instead of the 'play()' function from the base class. Option B is incorrect because virtual functions do not default to the base class implementation. Option C is incorrect because virtual functions do not generate runtime errors. Option D is also incorrect because the correct answer is A.