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
What is a friend function in C++?
Answer: A non-member function granted access to a class's private and protected members
A friend function is declared inside a class with the 'friend' keyword and can access private and protected members despite not being a member itself.
In the context of C++ class design, what does 'encapsulation' primarily mean?
Answer: Bundling data and methods that operate on that data together while hiding internal details
Encapsulation is the OOP principle of combining data and the functions that manipulate it into a class while restricting direct access to internal state.
What is the purpose of a move constructor introduced in C++11?
Answer: To transfer ownership of resources from a temporary object without copying
A move constructor transfers resources (like heap memory) from an expiring object (rvalue) to a new object, avoiding expensive deep copies.
Which operator must always be overloaded as a member function in C++?
Answer: operator=
The copy assignment operator (operator=) must be overloaded as a non-static member function because its left operand must be an lvalue of the class type.
What is a vtable (virtual table) in C++?
Answer: A runtime lookup table of function pointers used to resolve virtual function calls
A vtable is a per-class table of pointers to virtual functions, enabling the runtime dispatch that powers polymorphism.
What does 'final' do when applied to a C++11 class?
Answer: Prevents the class from being used as a base class
Declaring a class 'final' prohibits other classes from inheriting from it, locking the class hierarchy at that point.
Which of the following is true about static member variables in C++?
Answer: A static member variable is shared across all instances of the class
A static member variable belongs to the class itself rather than any individual instance, so all objects share a single copy.