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.


Which keyword is necessary in base class function declaration to allow polymorphism in C++?

  1. dynamic

  2. static

  3. virtual

  4. const

The correct answer is: virtual

A base class function declaration serves as a template for potential derived classes to inherit and implement in their own unique ways. The "virtual" keyword is necessary to ensure dynamic dispatch, which allows the correct implementation of the function to be called at runtime based on the actual type of object being referenced. This enables polymorphism, which is essential for creating different behaviors for different derived classes. Option A and B do not pertain to the concept of polymorphism and are not necessary for base class function declaration. Option D, "const," is not necessary for allowing polymorphism and instead pertains to the constantness of a variable.