โ† 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. Which rule of thumb states that if a class defines a destructor, copy constructor, or copy assignment operator, it likely needs all three?

    Answer: Rule of Three

    The Rule of Three states that if you explicitly define any of the destructor, copy constructor, or copy assignment operator, you should define all three.

  2. What is the effect of declaring a member function 'const' at the end of its declaration?

    Answer: It guarantees the function will not modify the object's state

    A const member function promises not to modify the object it is called on, allowing it to be called on const objects.

  3. In C++ inheritance, what is the order of constructor calls when a Derived class inherits from Base?

    Answer: Base constructor first, then Derived constructor

    Base class constructors always run before the derived class constructor to ensure the base subobject is fully initialized first.

  4. What is the difference between method overloading and method overriding in C++?

    Answer: Overloading defines multiple functions with the same name but different signatures in the same scope; overriding redefines a virtual base function in a derived class

    Overloading creates multiple functions with the same name but different parameters, while overriding provides a new implementation of a virtual function in a subclass.

  5. What does the 'override' specifier in C++11 do when applied to a virtual function in a derived class?

    Answer: It causes a compile-time error if the function does not actually override a base virtual function

    The override specifier tells the compiler to verify that the function actually overrides a base class virtual function, catching signature mismatches at compile time.

  6. Which design scenario best justifies using multiple inheritance in C++?

    Answer: When a class implements multiple unrelated interfaces or mix-in behaviors

    Multiple inheritance is most appropriate when a class must fulfill multiple distinct interface contracts or combine independent mix-in capabilities.

  7. What problem does the diamond inheritance problem describe in C++?

    Answer: Ambiguity and multiple copies of a shared base class when two classes inherit from the same base and a fourth class inherits from both

    The diamond problem arises when two classes share a common base and a class inherits from both, potentially creating two copies of the base subobject.