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!

Practice this question and more.


What is required in C++ to use a function for polymorphism?

  1. The inline keyword

  2. The static keyword

  3. The virtual keyword

  4. The explicit keyword

The correct answer is: The virtual keyword

Polymorphism in C++ refers to the ability of objects of different types to respond differently to the same function call. In order to achieve this, the virtual keyword is used in the function declaration to indicate that it can be overridden by derived classes. A The inline keyword is used to define a function which is expanded in line when it is called, it is not related to polymorphism. B: The static keyword is used to declare a function or variable that exists independently of any objects, it is also not related to polymorphism. D: The explicit keyword is used to prevent automatic type conversions, it also has no relation to polymorphism. Hence, the correct answer is C.