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

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

Master C++ with our comprehensive quiz based on 'Thinking in C++'. Test your knowledge through flashcards and multiple-choice questions to enhance your understanding of C++. Prepare effectively for your exam!

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 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.