Object-Oriented Programming (OOP) in C++ revolutionizes software design by organizing code around data (objects) rather than relying solely on functions and logic. Introduced by Bjarne Stroustrup as “C with Classes,” C++ fully supports the four fundamental pillars of OOP: encapsulation, abstraction, inheritance, and polymorphism. By utilizing access specifiers (public, private, protected), C++ enforces strict data hiding and memory security. Advanced features like virtual functions, abstract classes, and multiple inheritance give C++ immense architectural power and flexibility. Mastering C++ OOP principles is critical for building scalable, maintainable systems, preventing memory leaks through virtual destructors, and passing technical software engineering interviews.
C++ OOP MCQs Object-Oriented Programming
1 min read
Correct Answer: a) A programming paradigm based on objects
Explanation:
OOP organizes software around objects that combine data and behavior.
Correct Answer: b) A blueprint for objects
Explanation:
A class defines the data and operations that its objects will have.
Correct Answer: c) An instance of a class
Explanation:
Objects are concrete instances created from a class.
Correct Answer: d) Bundling data and methods together
Explanation:
Encapsulation keeps related data and behavior inside a class and controls access.
Correct Answer: a) private
Explanation:
Private members are not directly accessible from outside the class.
Correct Answer: b) Exposing only essential features
Explanation:
Abstraction hides implementation details and presents a clear interface.
Correct Answer: c) Deriving new classes from existing classes
Explanation:
Inheritance lets a new class reuse and extend an existing class.
Correct Answer: d) The same interface with different behavior
Explanation:
Polymorphism allows different classes to respond to the same interface.
Correct Answer: a) class
Explanation:
The class keyword introduces a class definition.
Correct Answer: b) private
Explanation:
Class members are private by default unless specified otherwise.
Correct Answer: c) public
Explanation:
Struct members are public by default unless specified otherwise.
Correct Answer: d) private
Explanation:
Private members can only be accessed by members and friends of that class.
Correct Answer: a) protected
Explanation:
Protected members are accessible in the class and its derived classes.
Correct Answer: b) It is inline by default
Explanation:
Member functions defined inside the class are implicitly inline.
Correct Answer: c) MyClass obj;
Explanation:
A variable declaration using the class name creates an object.
Correct Answer: d) Accessing object members
Explanation:
The dot operator accesses members through an object.
Correct Answer: a) new
Explanation:
new allocates memory and constructs objects in C++.
Correct Answer: b) delete
Explanation:
delete destroys objects and releases memory allocated by new.
Correct Answer: c) The same as the class name
Explanation:
Constructors have the same name as their class.
Correct Answer: d) It has no return type
Explanation:
Constructors do not specify a return type.
Correct Answer: a) When an object is created
Explanation:
Constructors initialize objects during creation.
Correct Answer: b) A constructor that can be called with no arguments
Explanation:
A default constructor can create an object without providing arguments.
Correct Answer: c) An object of the same class
Explanation:
A copy constructor initializes a new object from an existing object.
Correct Answer: d) ~MyClass
Explanation:
Destructors use the class name prefixed with a tilde.
Correct Answer: a) When an object is destroyed
Explanation:
Destructors clean up resources when object lifetime ends.
Correct Answer: b) Yes
Explanation:
Constructors can be overloaded with different parameter lists.
Correct Answer: c) Providing multiple constructors with different parameters
Explanation:
Overloading allows different ways to initialize objects.
Correct Answer: d) Initializing members before the constructor body runs
Explanation:
Initializer lists initialize members directly during construction.
Correct Answer: a) A non-static const data member
Explanation:
Const non-static data members need initialization before the constructor body.
Correct Answer: b) Implicit conversion from the constructor argument
Explanation:
explicit stops unintended implicit conversions during object creation.
Correct Answer: c) It requires direct initialization for that conversion
Explanation:
explicit constructors are used for direct initialization, not implicit conversion.
Correct Answer: d) Default constructor
Explanation:
Creating an object without arguments uses a default constructor.
Correct Answer: a) Copy constructor
Explanation:
Direct initialization from another object uses the copy constructor.
Correct Answer: b) Copy assignment operator
Explanation:
Assigning to an existing object uses copy assignment.
Correct Answer: c) Copy assignment operator
Explanation:
The Rule of Three includes destructor, copy constructor, and copy assignment.
Correct Answer: d) Move assignment operator
Explanation:
The Rule of Five adds move constructor and move assignment.
Correct Answer: a) A default constructor
Explanation:
The compiler can implicitly declare a default constructor when needed.
Correct Answer: b) A default destructor
Explanation:
The compiler provides an implicit destructor if none is declared.
Correct Answer: c) A pointer to the current object
Explanation:
Inside member functions, this points to the object on which the function is called.
Correct Answer: d) No
Explanation:
Static member functions are not associated with an object instance.
Correct Answer: a) It is shared by all objects of the class
Explanation:
Static data members belong to the class, not to individual objects.
Correct Answer: b) Using the class name
Explanation:
Static member functions can be called without an object.
Correct Answer: c) Outside the class definition
Explanation:
Static data members typically need a separate definition outside the class.
Correct Answer: d) It promises not to modify non-mutable members
Explanation:
const member functions cannot change non-mutable member variables.
Correct Answer: a) A member to be modified in a const member function
Explanation:
mutable members can change even inside const member functions.
Correct Answer: b) A non-member function that can access private members
Explanation:
friend functions are granted access to private and protected members.
Correct Answer: c) Can access private members of the class that declares it friend
Explanation:
Friendship gives another class access to private and protected members.
Correct Answer: d) ::
Explanation:
The scope resolution operator cannot be overloaded.
Correct Answer: a) +
Explanation:
Arithmetic operators such as + can be overloaded for class types.
Correct Answer: b) .
Explanation:
The member access operator . cannot be overloaded.
Correct Answer: c) As a non-member or friend function
Explanation:
The left operand is usually ostream, so a non-member is natural.
Correct Answer: d) A virtual function declared with = 0
Explanation:
A pure virtual function has no required implementation in the base class.
Correct Answer: a) A class that cannot be instantiated
Explanation:
Abstract classes define interfaces and cannot create direct objects.
Correct Answer: b) At least one pure virtual function
Explanation:
A class with a pure virtual function cannot be instantiated.
Correct Answer: c) Runtime polymorphism
Explanation:
virtual allows derived classes to override functions selected at runtime.
Correct Answer: d) Redefining a virtual function in a derived class
Explanation:
An override provides a derived implementation of a base virtual function.
Correct Answer: a) override
Explanation:
override makes the compiler check that the function overrides a base function.
Correct Answer: b) Prevents overriding
Explanation:
A final virtual function cannot be overridden by derived classes.
Correct Answer: c) When deleting derived objects through base pointers
Explanation:
A virtual destructor ensures the derived destructor runs.
Correct Answer: d) It can cause undefined behavior
Explanation:
Without a virtual destructor, only the base destructor may run.
Correct Answer: a) Virtual functions
Explanation:
Virtual function dispatch selects implementations at runtime.
Correct Answer: b) Function overloading or templates
Explanation:
Compile-time polymorphism resolves calls during compilation.
Correct Answer: c) Using the same function name with different parameters
Explanation:
Overloaded functions differ by parameter types or counts.
Correct Answer: d) Operator behavior for class types
Explanation:
Overloading defines how operators behave for user-defined types.
Correct Answer: a) It can inherit members from a base class
Explanation:
Derived classes extend base classes with new or overridden members.
Correct Answer: b) class D : public B
Explanation:
C++ uses a colon and access specifier for inheritance.
Correct Answer: c) public
Explanation:
Public inheritance preserves public access for base members.
Correct Answer: d) protected
Explanation:
Protected inheritance lowers public base members to protected.
Correct Answer: a) private
Explanation:
Private inheritance makes inherited members private in the derived class.
Correct Answer: b) Before the derived constructor body
Explanation:
Base subobjects are initialized before derived members and body.
Correct Answer: c) After the derived destructor body
Explanation:
Destruction proceeds from derived to base.
Correct Answer: d) Base then derived
Explanation:
Base classes are constructed before derived classes.
Correct Answer: a) Derived then base
Explanation:
Derived destructors run before base destructors.
Correct Answer: b) A class inherits from more than one base class
Explanation:
A derived class can have several direct bases.
Correct Answer: c) Multiple inheritance paths to the same base class
Explanation:
Two paths to one base can create ambiguity.
Correct Answer: d) Virtual inheritance
Explanation:
Virtual inheritance creates one shared base subobject.
Correct Answer: a) One shared base subobject
Explanation:
Virtual inheritance avoids duplicated base parts.
Correct Answer: b) virtual
Explanation:
The virtual keyword in the base list enables virtual inheritance.
Correct Answer: c) Has-a
Explanation:
Composition means one object contains another.
Correct Answer: d) Is-a
Explanation:
A derived object is a kind of base object.
Correct Answer: a) Composition
Explanation:
Composition can combine objects while keeping implementation hidden.
Correct Answer: b) An abstract class with pure virtual functions
Explanation:
Pure virtual functions define an interface for derived classes.
Correct Answer: c) A class that can be instantiated
Explanation:
A concrete class has implementations for all required functions.
Correct Answer: d) A base pointer pointing to a Derived object
Explanation:
A base pointer can refer to a derived object.
Correct Answer: a) A virtual function
Explanation:
Virtual dispatch selects the derived implementation.
Correct Answer: b) Static pointer type
Explanation:
Non-virtual calls are resolved using the pointer type.
Correct Answer: c) Compile-time resolution
Explanation:
Static binding decides the function call during compilation.
Correct Answer: d) Runtime resolution
Explanation:
Dynamic binding selects functions while the program runs.
Correct Answer: a) Pointers to virtual functions
Explanation:
The vtable stores addresses of virtual functions for dispatch.
Correct Answer: b) A pointer in an object to its vtable
Explanation:
Objects with virtual functions often contain a vptr.
Correct Answer: c) During construction
Explanation:
The constructor sets up the object's vptr.
Correct Answer: d) No
Explanation:
Constructors cannot be virtual because the object type is being created.
Correct Answer: a) Yes
Explanation:
Virtual destructors support safe polymorphic deletion.
Correct Answer: b) No
Explanation:
Constructors, including copy constructors, cannot be virtual.
Correct Answer: c) No
Explanation:
Virtual dispatch requires an object, while static functions do not have this.
Correct Answer: d) Yes
Explanation:
const member functions can be virtual and overridden.
Correct Answer: a) Copying only the base part when a derived object is copied as a base value
Explanation:
Value assignment to a base type can lose derived data.
Correct Answer: b) Using pointers or references
Explanation:
Pointers and references preserve the dynamic type.
Correct Answer: c) A polymorphic source type
Explanation:
dynamic_cast needs virtual functions for runtime type checking.
Correct Answer: d) nullptr
Explanation:
For pointer types, a failed dynamic_cast returns nullptr.
Correct Answer: a) dynamic_cast
Explanation:
dynamic_cast checks the actual runtime type.
Correct Answer: b) It does not check runtime type
Explanation:
static_cast assumes the cast is valid.
Correct Answer: c) Runtime Type Information
Explanation:
RTTI provides type identity features such as dynamic_cast and typeid.
Correct Answer: d) Type information
Explanation:
typeid returns a type_info object describing the type.
Correct Answer: a) typeinfo
Explanation:
The typeinfo header defines type_info.
Correct Answer: b) Polymorphic
Explanation:
Virtual functions make a class capable of runtime dispatch.
Correct Answer: c) Abstract
Explanation:
Pure virtual functions prevent direct instantiation.
Correct Answer: d) Yes, separately outside the class
Explanation:
A pure virtual function can still be defined explicitly.
Correct Answer: a) virtual ~Base() { }
Explanation:
The virtual keyword appears before the destructor declaration.
Correct Answer: b) After the function declaration in the derived class
Explanation:
override follows the member function declarator.
Correct Answer: c) After a virtual function or after a class name
Explanation:
final can prevent overriding or inheritance.
Correct Answer: d) Derived cannot be used as a base class
Explanation:
A final class cannot be inherited.
Correct Answer: a) Further overriding
Explanation:
Derived classes cannot override a final virtual function.
Correct Answer: b) The base member may be hidden
Explanation:
Name hiding can shadow base class members.
Correct Answer: c) A derived member shadows a base member
Explanation:
The derived declaration can hide same-named base declarations.
Correct Answer: d) Using Base::member
Explanation:
Scope resolution selects the base class member.
Correct Answer: a) Bring base overloaded functions into scope
Explanation:
using Base::name can prevent hiding of overloads.
Correct Answer: b) using Base::Base;
Explanation:
A using declaration can inherit base constructors.
Correct Answer: c) A class defined inside another class
Explanation:
Nested classes are declared within the scope of another class.
Correct Answer: d) It is scoped inside the enclosing class
Explanation:
A nested class name is scoped by its enclosing class.
Correct Answer: a) A class defined inside a function
Explanation:
Local classes are declared within function scope.
Correct Answer: b) No
Explanation:
Local classes cannot contain static data members.
Correct Answer: c) No
Explanation:
Local class member functions must be defined inside the class.
Correct Answer: d) Yes
Explanation:
Local classes may define constructors and destructors inside the class.
Correct Answer: a) Yes, with a forward declaration
Explanation:
class MyClass; declares an incomplete type.
Correct Answer: b) Reducing dependencies and incomplete type usage
Explanation:
Forward declarations can reduce header coupling.
Correct Answer: c) A declared but not defined class
Explanation:
Incomplete types lack a full definition.
Correct Answer: d) No
Explanation:
Objects require a complete class definition.
Correct Answer: a) Yes
Explanation:
Pointers can refer to incomplete types.
Correct Answer: b) Pointer to implementation to hide details
Explanation:
PIMPL separates interface from implementation.
Correct Answer: c) Resource Acquisition Is Initialization
Explanation:
RAII ties resource management to object lifetime.
Correct Answer: d) Object lifetime
Explanation:
Resources are acquired in constructors and released in destructors.
Correct Answer: a) unique_ptr
Explanation:
unique_ptr manages dynamically allocated memory.
Correct Answer: b) Exclusive
Explanation:
Only one unique_ptr should own a resource.
Correct Answer: c) Reference-counted shared ownership
Explanation:
shared_ptr deletes the object when the last owner is gone.
Correct Answer: d) A non-owning observer
Explanation:
weak_ptr observes shared_ptr without extending ownership.
Correct Answer: a) weak_ptr
Explanation:
weak_ptr avoids increasing the reference count.
Correct Answer: b) Creates a shared_ptr efficiently
Explanation:
make_shared allocates the object and control block together.
Correct Answer: c) Transferring resources from one object to another
Explanation:
Move semantics avoid unnecessary copying.
Correct Answer: d) &&
Explanation:
Rvalue references use double ampersand.
Correct Answer: a) Casts an object to an rvalue reference
Explanation:
std::move enables move operations but does not move by itself.
Correct Answer: b) Transfers resources from the source object
Explanation:
Move constructors take resources from rvalue sources.
Correct Answer: c) Valid but unspecified
Explanation:
Moved-from objects should be safe to destroy or assign.
Correct Answer: d) Double deletion
Explanation:
Two objects may delete the same resource.
Correct Answer: a) Copies owned resources
Explanation:
Deep copying duplicates the underlying resource.
Correct Answer: b) Copy assignment safely
Explanation:
It uses a temporary copy and swap to provide strong exception safety.
Correct Answer: c) Exchanging object states
Explanation:
swap exchanges internals of two objects efficiently.
Correct Answer: d) The function is not expected to throw
Explanation:
noexcept can enable optimizations and safer move operations.
Correct Answer: a) To enable optimizations and safe container behavior
Explanation:
Containers may prefer noexcept move operations.
Correct Answer: b) A function object
Explanation:
A functor is an object that can be called like a function.
Correct Answer: c) An anonymous function object
Explanation:
Lambdas create callable objects inline.
Correct Answer: d) Capture nothing
Explanation:
An empty capture list uses no local variables.
Correct Answer: a) Capture by reference
Explanation:
All used local variables are captured by reference.
Correct Answer: b) Capture by value
Explanation:
All used local variables are copied into the lambda.
Correct Answer: c) Yes, if signatures are compatible
Explanation:
std::function can hold callable objects.
Correct Answer: d) A lambda using auto parameters
Explanation:
Generic lambdas accept arguments of deduced types.
Correct Answer: a) A generic blueprint for types or functions
Explanation:
Templates allow code parameterized by types.
Correct Answer: b) Compile-time generic programming
Explanation:
Templates generate type-specific code during compilation.
Correct Answer: c) template
Explanation:
The template keyword introduces template parameters.
Correct Answer: d) template <typename T> class C { }
Explanation:
Template parameters appear in angle brackets after template.
Correct Answer: a) Yes
Explanation:
Different template or parameter combinations can be overloaded.
Correct Answer: b) A custom definition for a specific type
Explanation:
Specializations tailor templates for particular arguments.
Correct Answer: c) Substitution failure is not an error
Explanation:
Failed template substitution removes candidates instead of causing an error.
Correct Answer: d) Compile-time constant evaluation
Explanation:
constexpr functions and variables can be evaluated at compile time.
Correct Answer: a) Yes, if requirements are met
Explanation:
constexpr constructors allow compile-time object initialization.
Correct Answer: b) A scoped enumeration
Explanation:
enum class keeps enumerators in the enum scope.
Correct Answer: c) Groups identifiers
Explanation:
Namespaces organize names and avoid collisions.
Correct Answer: d) Name collisions
Explanation:
Importing many names can create ambiguity.
Correct Answer: a) ::
Explanation:
It accesses names in namespaces, classes, and global scope.
Correct Answer: b) Accesses a member through a pointer
Explanation:
Arrow combines dereference and member access.
Correct Answer: c) A pointer to a member of a class
Explanation:
It points to a member rather than an object address.
Correct Answer: d) .*
Explanation:
The .* operator applies a pointer-to-member to an object.
Correct Answer: a) ->*
Explanation:
The ->* operator applies a pointer-to-member through a pointer.
Correct Answer: b) Hiding the concrete type behind an interface
Explanation:
Type erasure stores different types behind a common interface.
Correct Answer: c) Type erasure
Explanation:
std::function can hold many callable types with a signature.
Correct Answer: d) Specifying obligations for interfaces
Explanation:
Contracts define preconditions, postconditions, and invariants.
Correct Answer: a) A set of OOP design principles
Explanation:
SOLID guides maintainable object-oriented design.
Correct Answer: b) A class should have one reason to change
Explanation:
Each class should focus on one responsibility.
Correct Answer: c) Open for extension, closed for modification
Explanation:
Behavior can be extended without changing existing code.
Correct Answer: d) Derived objects should be usable through base interfaces
Explanation:
Derived classes must preserve base class expectations.
Correct Answer: a) Avoid large, forced interfaces
Explanation:
Clients should not depend on unneeded methods.
Correct Answer: b) Depend on abstractions
Explanation:
High-level modules should rely on stable interfaces.
Correct Answer: c) Strong dependency between classes
Explanation:
Tightly coupled classes are hard to change independently.
Correct Answer: d) Components are relatively independent
Explanation:
Loose coupling improves maintainability.
Correct Answer: a) Related responsibilities are kept together
Explanation:
Cohesive classes have focused responsibilities.
Correct Answer: b) Unrelated responsibilities together
Explanation:
Low cohesion makes classes harder to understand.
Correct Answer: c) Car contains Engine
Explanation:
Containment models ownership or composition.
Correct Answer: d) Square inherits Shape
Explanation:
Inheritance expresses a subtype relationship.
Correct Answer: a) One class uses another through methods or parameters
Explanation:
Uses relationships are often temporary dependencies.
Correct Answer: b) Association without necessarily owning the object
Explanation:
Aggregation is a weaker has-a relationship than composition.
Correct Answer: c) Strong has-a with lifetime ownership
Explanation:
Composed parts often live and die with the owner.
Correct Answer: d) Function selection based on multiple objects
Explanation:
C++ natively dispatches on one dynamic type.
Correct Answer: a) Only pure virtual functions
Explanation:
Interfaces often avoid state.
Correct Answer: b) Providing a common interface for derived classes
Explanation:
Abstract bases define shared behavior.
Correct Answer: c) An override returning a derived type
Explanation:
Overrides can return more specific pointer or reference types.
Correct Answer: d) Related base and derived return types with pointers or references
Explanation:
Covariance works with related class hierarchies.
Correct Answer: a) From construction to destruction
Explanation:
Lifetime is the period an object exists.
Correct Answer: b) Automatic storage
Explanation:
Stack objects are created and destroyed automatically.
Correct Answer: c) Dynamic allocation via new
Explanation:
Heap objects require manual or smart pointer management.
Correct Answer: d) Allocated memory that is not freed
Explanation:
Leaks exhaust memory over time.
Correct Answer: a) A pointer to freed or deleted memory
Explanation:
Dereferencing it causes undefined behavior.
Correct Answer: b) Deleting the same dynamic memory twice
Explanation:
Double free corrupts memory.
Correct Answer: c) No guaranteed result
Explanation:
The standard imposes no requirements on undefined behavior.
Correct Answer: d) Virtual function dispatch
Explanation:
The vtable enables runtime selection of overrides.
Correct Answer: a) class B : virtual public A
Explanation:
virtual in the base list creates a virtual base.
Correct Answer: b) Scope resolution or virtual inheritance
Explanation:
Qualify the base or share one base subobject.
Correct Answer: c) It may include a virtual base pointer
Explanation:
Implementations need to locate the shared base.
Correct Answer: d) A class with at least one virtual function
Explanation:
Polymorphic classes support dynamic dispatch.
Correct Answer: a) A class that cannot be inherited
Explanation:
final prevents derivation.
Correct Answer: b) final
Explanation:
C++ uses final to prevent inheritance.
Correct Answer: c) Controlling deletion through derived classes or factories
Explanation:
Protected destructors restrict who can destroy objects.
Correct Answer: d) Preventing direct object creation
Explanation:
Private constructors restrict instantiation.
Correct Answer: a) A private constructor and static accessor
Explanation:
Singleton controls creation of one instance.
Correct Answer: b) Creates objects without exposing exact creation logic
Explanation:
Factories encapsulate object creation.
Correct Answer: c) Notifies dependent objects about changes
Explanation:
Observers subscribe to subject state changes.
Correct Answer: d) Converts one interface into another
Explanation:
Adapters make incompatible interfaces work together.
Correct Answer: a) Adds behavior dynamically
Explanation:
Decorators wrap objects to extend functionality.
Correct Answer: b) Interchangeable algorithms
Explanation:
Strategy selects behavior at runtime.
Correct Answer: c) Encapsulates a request as an object
Explanation:
Commands can be queued, logged, or undone.
Correct Answer: d) Defines an algorithm skeleton in a base class
Explanation:
Derived classes override selected steps.
Correct Answer: a) Addresses
Explanation:
Pointer comparison checks location, not value.
Correct Answer: b) operator==
Explanation:
Equality can be defined for class types.
Correct Answer: c) Compiler omission of a copy operation
Explanation:
The compiler can avoid creating temporary copies.
Correct Answer: d) Reduces temporary objects
Explanation:
RVO constructs return values directly where needed.
Correct Answer: a) An unnamed object created by an expression
Explanation:
Temporaries are often created during evaluation.
Correct Answer: b) Yes
Explanation:
A const lvalue reference can bind to a temporary.
Correct Answer: c) A constructor that can convert from another type
Explanation:
It creates an object from a compatible argument.
Correct Answer: d) Implicit unwanted conversions
Explanation:
Implicit conversions can cause surprising behavior.
Correct Answer: a) explicit
Explanation:
explicit stops implicit conversion during initialization.
Correct Answer: b) operator Type()
Explanation:
It converts an object to another type.
Correct Answer: c) Converts the object to int
Explanation:
Conversion operators define type conversion.
Correct Answer: d) Implicit conversion in many contexts
Explanation:
explicit requires a direct cast or initialization.
Correct Answer: a) Ask the compiler to generate the default implementation
Explanation:
Defaulted functions use compiler-generated behavior.
Correct Answer: b) Prevent use of the function
Explanation:
Deleted functions cause compile errors when used.
Correct Answer: c) To prevent copying
Explanation:
Deleted copy constructors make objects non-copyable.
Correct Answer: d) A constructor, destructor, copy, or move operation
Explanation:
Special members control object lifecycle operations.
Correct Answer: a) Initializing an aggregate with braces
Explanation:
Aggregates can be initialized element by element.
Correct Answer: b) Plain Old Data
Explanation:
POD types have simple layout and copying rules.
Correct Answer: c) It can be copied by copying its object representation
Explanation:
Trivially copyable types can be moved as bytes.
Correct Answer: d) A type with C-compatible layout
Explanation:
Standard layout helps interoperability with C.
Correct Answer: a) Controlled access to data
Explanation:
Encapsulation protects internal state.
Correct Answer: b) Simplifying how code is used
Explanation:
Abstraction hides complexity behind interfaces.
Correct Answer: c) Code reuse and polymorphism
Explanation:
Inheritance shares behavior across related classes.
Correct Answer: d) Different implementations through a common interface
Explanation:
Polymorphism enables flexible, extensible designs.
Correct Answer: a) A function belonging to a class
Explanation:
Member functions define class behavior.
Correct Answer: b) A variable inside a class
Explanation:
Data members store object state.
Correct Answer: c) A condition that should hold for a valid object
Explanation:
Invariants preserve object consistency.
Correct Answer: d) Using const to enforce immutability
Explanation:
const correctness improves safety and clarity.
Correct Answer: a) Its non-mutable state cannot be modified
Explanation:
const objects cannot be changed through non-mutable members.
Correct Answer: b) It promises not to modify object state
Explanation:
const member functions support const correctness.
Related Posts
NewNewNew
No Image
C++ Templates - MCQs
1. What is OOP? a) A programming paradigm based on objects b) A procedural-only style c) A hardware design method…
October 19, 2026By MCQs Generator
No Image
C++ Arrays / Lists - MCQs
1. What is OOP? a) A programming paradigm based on objects b) A procedural-only style c) A hardware design method…
October 20, 2026By MCQs Generator

C++ Memory Management MCQs
Memory management in C++ empowers developers with direct control over hardware resources, primarily through the allocation and deallocation of memory…
October 20, 2026By MCQs Generator








