โ† All CPP Flashcard Decks

Object-Oriented Programming & Class Design Flashcards

7 cards from real CPP practice questions. Tap to flip, then mark Knew It or Still Learning โ€” missed cards come back until you master them.

Read the first 7 Object-Oriented Programming & Class Design flashcards as text
  1. What is the key difference between composition and inheritance as design strategies?

    Answer: Composition models a 'has-a' relationship; inheritance models an 'is-a' relationship

    Composition embeds objects of other classes (has-a), while inheritance derives from a base class (is-a), each representing a fundamentally different relationship.

  2. Which statement accurately describes an abstract class in C++?

    Answer: A class that contains at least one pure virtual function and cannot be instantiated directly

    An abstract class has one or more pure virtual functions (= 0) and cannot be used to create objects; it must be subclassed and the pure virtuals overridden.

  3. What is the purpose of the 'mutable' keyword on a class data member?

    Answer: It allows the member to be modified even inside a const member function

    A mutable member can be modified by const member functions, which is useful for caches, mutexes, or lazy-computed values.

  4. In C++, what is operator overloading?

    Answer: Providing a user-defined implementation of a built-in operator for a class type

    Operator overloading lets you define how standard C++ operators (like +, ==, <<) behave when applied to objects of your class.

  5. What is the Liskov Substitution Principle (LSP) in OOP?

    Answer: Objects of a derived class should be substitutable for objects of the base class without altering program correctness

    LSP states that if S is a subtype of T, objects of type T may be replaced with objects of type S without changing the desirable properties of the program.

  6. What happens when a constructor throws an exception before the object is fully constructed in C++?

    Answer: No destructor is called for the incompletely constructed object, but destructors for fully constructed member subobjects are called

    If a constructor throws, the object's destructor is not invoked, but destructors of any fully constructed member objects and base subobjects are called.

  7. Which statement best describes the purpose of 'virtual inheritance' in C++?

    Answer: It ensures only one instance of a common base class exists when multiple derived classes inherit from it

    Virtual inheritance causes a single shared instance of the common base class subobject to be created, resolving the ambiguity of the diamond inheritance problem.