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 concept does the example of object slicing demonstrate?

  1. Polymorphism

  2. Encapsulation

  3. Inheritance

  4. Memory management

The correct answer is: Polymorphism

The concept of object slicing is the result of data being lost when assigning a derived class object to a base class object. This limitation arises due to the compiler not recognizing the full capabilities of the derived class, and therefore only copying the base-class portion of the object into the new variable. This example specifically demonstrates polymorphism, as the derived class object is temporarily treated as a base class object, leading to data loss. Encapsulation refers to the bundling of data and methods within an object, while inheritance is the process of deriving new classes from existing ones. Memory management, on the other hand, is the act of managing computer memory usage in a program. Therefore, the correct concept demonstrated in this example is polymorphism.