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.


Can a pure virtual function have a definition in C++?

  1. Yes, always

  2. No, never

  3. Yes, but only in derived classes

  4. Yes, in the base class

The correct answer is: Yes, in the base class

A This is incorrect because pure virtual functions cannot have any definition in the base class. B: This is also incorrect because a pure virtual function can have a declaration with no definition in the base class. C: While this may seem correct, it is not the most accurate answer. A pure virtual function can have a definition in a derived class, but it must also be overridden in any further derived classes. D: This is the correct answer. A pure virtual function can have a definition in the base class, as long as it is not used to create objects of that class and is overridden in any further derived classes.