In C++, a class is a fundamental building block of Object-Oriented Programming (OOP) that acts as a user-defined blueprint for creating objects. It encapsulates both data members (attributes) and member functions (methods) into a single logical unit, ensuring data hiding through access specifiers like private, protected, and public. An object is a distinct instance of a class that occupies memory and allows interaction with the defined class members. Understanding classes and objects is critical for mastering C++ memory management, modular programming, and advanced OOP concepts like inheritance and polymorphism. Grasping object instantiation, constructor invocation, and scope resolution is essential for any aspiring C++ developer.
C++ Classes and Objects - MCQs
1 min read
Correct Answer: a) class
Explanation:
The 'class' keyword is used to define a class in C++.
Correct Answer: b) private
Explanation:
By default, all members of a class are private in C++.
Correct Answer: a) public
Explanation:
By default, all members of a struct are public in C++.
Correct Answer: b) .
Explanation:
The dot (.) operator is used to access members of a class through an object instance.
Correct Answer: b) ->
Explanation:
The arrow (->) operator is used to access members of a class through a pointer to an object.
Correct Answer: b) 1
Explanation:
An empty class has a size of 1 byte to ensure that two different objects have distinct memory addresses.
Correct Answer: c) Dot operator
Explanation:
The dot operator is for object member access, not for defining functions outside the class. The scope resolution operator (::) is used for that.
Correct Answer: b) inline
Explanation:
Functions defined inside the class body are implicitly inline, suggesting the compiler to replace the call with the function body.
Correct Answer: b) They can be defined outside the class using ::
Explanation:
Member functions can be defined outside the class using the scope resolution operator (::).
Correct Answer: a) MyClass obj;
Explanation:
Objects are declared using the class name followed by the object name and a semicolon.
Correct Answer: b) private
Explanation:
Private members are accessible only within the class itself and by friend functions/classes.
Correct Answer: c) protected
Explanation:
Protected members are accessible within the class and its derived classes, but not from outside.
Correct Answer: b) No, never
Explanation:
Private members cannot be accessed directly by derived classes. They must use protected or public members.
Correct Answer: b) Allow access from anywhere
Explanation:
Public members can be accessed from anywhere the object is visible.
Correct Answer: c) The only difference is the default access specifier
Explanation:
In C++, struct and class are functionally identical except for the default access specifier (public for struct, private for class).
Correct Answer: b) A special member function used to initialize objects
Explanation:
A constructor is a special member function that initializes objects of a class.
Correct Answer: b) They have the same name as the class
Explanation:
Constructors must have the exact same name as the class and do not have a return type.
Correct Answer: a) A constructor with no parameters
Explanation:
A default constructor is a constructor that takes no arguments (or all arguments have default values).
Correct Answer: b) When an object is initialized with another object of the same class
Explanation:
A copy constructor is called when a new object is initialized using an existing object of the same class.
Correct Answer: b) ClassName(const ClassName &obj)
Explanation:
A copy constructor takes a constant reference to an object of the same class to avoid infinite recursion and allow const objects.
Correct Answer: b) No
Explanation:
Constructors cannot be virtual because the object is not fully created yet, and the vptr is not initialized.
Correct Answer: b) The compiler provides a default constructor
Explanation:
If no constructor is defined, the compiler implicitly generates a default constructor.
Correct Answer: c) No, never
Explanation:
Constructors do not have a return type, not even void.
Correct Answer: a) Having multiple constructors with different parameters
Explanation:
Constructor overloading means having multiple constructors in a class with different parameter lists.
Correct Answer: b) Copy constructor
Explanation:
When an object is passed by value, a copy is made, invoking the copy constructor.
Correct Answer: b) A special member function that cleans up before an object is destroyed
Explanation:
A destructor is called automatically when an object goes out of scope or is explicitly deleted.
Correct Answer: a) ~ClassName()
Explanation:
A destructor is declared with a tilde (~) followed by the class name and no parameters.
Correct Answer: b) No
Explanation:
Destructors take no parameters and cannot be overloaded.
Correct Answer: b) No
Explanation:
Since destructors take no parameters, they cannot be overloaded.
Correct Answer: b) When the object goes out of scope
Explanation:
Destructors for local objects are called automatically when they go out of scope.
Correct Answer: b) Reverse order of creation
Explanation:
Destructors are called in the reverse order of their construction (LIFO).
Correct Answer: b) Points to the current object invoking the member function
Explanation:
The 'this' pointer is an implicit pointer available to all non-static member functions, pointing to the object that called the function.
Correct Answer: a) ClassName*
Explanation:
In a non-const member function, 'this' is a pointer of type ClassName*.
Correct Answer: b) const ClassName*
Explanation:
In a const member function, 'this' is a pointer of type const ClassName*, preventing modification of object data.
Correct Answer: b) No
Explanation:
Static member functions do not belong to any specific object, so they do not have a 'this' pointer.
Correct Answer: a) Method chaining
Explanation:
Returning '*this' (a reference to the object) allows method chaining, like obj.func1().func2().
Correct Answer: b) A member shared by all objects of the class
Explanation:
Static data members are shared among all instances of the class; only one copy exists.
Correct Answer: b) Outside the class definition in a source file
Explanation:
Static data members must be defined and initialized outside the class, typically in a .cpp file.
Correct Answer: b) Using the class name and scope resolution operator
Explanation:
Static member functions can be called using the class name directly, e.g., ClassName::func().
Correct Answer: b) No
Explanation:
Static member functions do not have a 'this' pointer, so they cannot access non-static members directly.
Correct Answer: b) A non-member function that can access private members of the class
Explanation:
A friend function is not a member of the class but is granted access to its private and protected members.
Correct Answer: a) friend
Explanation:
The 'friend' keyword is used inside the class to grant access to a non-member function.
Correct Answer: b) No
Explanation:
Friend functions are normal external functions, not members of the class.
Correct Answer: a) Yes
Explanation:
An entire class can be declared as a friend, making all its member functions friends of the other class.
Correct Answer: b) No
Explanation:
Friendship is not inherited. Derived classes do not automatically inherit friend status.
Correct Answer: b) No
Explanation:
Friendship is not mutual. If A is a friend of B, B is not automatically a friend of A.
Correct Answer: a) Yes
Explanation:
The access specifier where a friend is declared does not matter; it grants access regardless of where it is placed.
Correct Answer: b) A function that cannot modify the object's non-mutable data members
Explanation:
A const member function promises not to modify the object's state (except mutable members).
Correct Answer: b) void func() const
Explanation:
The 'const' keyword is placed after the parameter list in the function declaration.
Correct Answer: b) No
Explanation:
A const object can only call const member functions to ensure its state is not modified.
Correct Answer: b) Allowing a member variable to be modified in a const function
Explanation:
Mutable members can be modified even within const member functions or const objects.
Correct Answer: b) No
Explanation:
Static members are not part of the object's state in the same way, and the compiler forbids making them mutable.
Correct Answer: b) Copying the object by copying the values of its members, including pointers
Explanation:
Shallow copy copies pointer addresses, meaning both objects point to the same dynamically allocated memory.
Correct Answer: b) Copying the object and allocating new memory for pointer members
Explanation:
Deep copy allocates new memory and copies the actual data, ensuring independent objects.
Correct Answer: b) When the class manages dynamic memory via pointers
Explanation:
If a class has pointers to dynamic memory, a deep copy is needed to avoid double deletion and shared state issues.
Correct Answer: b) =
Explanation:
The '=' operator is used to assign the value of one object to another existing object.
Correct Answer: b) A default shallow copy assignment operator
Explanation:
The compiler generates a default assignment operator that performs a member-wise shallow copy.
Correct Answer: b) If a class defines one of destructor, copy constructor, or copy assignment, it should probably define all three
Explanation:
The Rule of Three states that if you need a custom destructor, copy constructor, or copy assignment operator, you likely need all three to manage resources properly.
Correct Answer: a) Creating a new class from an existing class
Explanation:
Inheritance allows a class (derived) to acquire properties and methods of another class (base).
Correct Answer: b) :
Explanation:
A single colon (:) is used to denote inheritance, e.g., class Derived : public Base.
Correct Answer: b) private
Explanation:
When a class inherits from another class without specifying an access specifier, it defaults to private inheritance.
Correct Answer: a) public
Explanation:
When a struct inherits from another struct/class without specifying an access specifier, it defaults to public inheritance.
Correct Answer: b) They remain public
Explanation:
In public inheritance, public members of the base class remain public in the derived class.
Correct Answer: c) They become private
Explanation:
In private inheritance, both public and protected members of the base class become private in the derived class.
Correct Answer: b) Inheriting from more than one base class
Explanation:
Multiple inheritance allows a derived class to inherit from two or more base classes.
Correct Answer: b) Ambiguity when two base classes inherit from the same grandparent class
Explanation:
The diamond problem occurs when a class inherits from two classes that both inherit from a common base, causing ambiguity.
Correct Answer: b) Using virtual inheritance
Explanation:
Virtual inheritance ensures that only one instance of the common base class is inherited.
Correct Answer: b) The ability of a function or object to take on many forms
Explanation:
Polymorphism allows entities like functions or objects to be processed differently based on their context or type.
Correct Answer: b) Function overloading and operator overloading
Explanation:
Compile-time polymorphism is achieved through function overloading, operator overloading, and templates.
Correct Answer: b) Function overriding using virtual functions
Explanation:
Run-time polymorphism is achieved using virtual functions and function overriding in inheritance.
Correct Answer: b) virtual
Explanation:
The 'virtual' keyword is used in the base class to allow derived classes to override the function.
Correct Answer: b) Redefining a base class function in the derived class with the same signature
Explanation:
Function overriding occurs when a derived class provides a specific implementation of a virtual function already defined in its base class.
Correct Answer: b) Defining a function in the derived class with the same name but different signature as the base class
Explanation:
If a derived class defines a function with the same name but different parameters, it hides all base class functions with that name.
Correct Answer: b) No
Explanation:
Virtual functions must be non-static member functions because they rely on the object's vptr for dynamic binding.
Correct Answer: b) No
Explanation:
A virtual function must be a member of a class, while a friend function is not a member.
Correct Answer: b) No
Explanation:
Constructors cannot be virtual because the object is not fully constructed when the constructor is called, so the vptr is not set.
Correct Answer: b) Yes, if the class is intended to be used as a base class
Explanation:
Making base class destructors virtual ensures that the derived class destructor is called when deleting through a base class pointer.
Correct Answer: a) A virtual function with no implementation in the base class
Explanation:
A pure virtual function is declared by assigning 0 in its declaration, e.g., virtual void func() = 0.
Correct Answer: b) A class that contains at least one pure virtual function
Explanation:
A class becomes abstract if it has at least one pure virtual function, and it cannot be instantiated.
Correct Answer: b) No
Explanation:
Abstract classes cannot be instantiated directly; they must be derived from.
Correct Answer: a) Yes
Explanation:
Abstract classes can have constructors, which are called when a derived class object is created.
Correct Answer: b) To provide a common interface and base for derived classes
Explanation:
Abstract classes define a common interface that derived classes must implement, enforcing a contract.
Correct Answer: a) A class defined inside another class
Explanation:
A nested class is a class defined within the scope of another enclosing class.
Correct Answer: b) No, unless declared as a friend
Explanation:
A nested class does not have special access to the enclosing class's private members unless explicitly granted friend status.
Correct Answer: b) The scope of the enclosing class
Explanation:
A nested class is scoped within the enclosing class and must be accessed using the enclosing class name.
Correct Answer: a) A class defined inside a function
Explanation:
A local class is defined inside a function body and its scope is limited to that function.
Correct Answer: b) No, unless they are static or enum
Explanation:
Local classes cannot access non-static local variables of the enclosing function, but can access static variables and enums.
Correct Answer: b) 1
Explanation:
Static members are not part of the object's size. An empty class or one with only static members has a size of 1 byte.
Correct Answer: b) Adding extra bytes to align data members in memory
Explanation:
Compilers add padding bytes between data members to ensure proper memory alignment for hardware efficiency.
Correct Answer: b) It can affect size due to memory padding
Explanation:
Reordering members from largest to smallest can minimize padding and reduce the overall size of the class.
Correct Answer: d) Size of data members plus the size of a vptr
Explanation:
A class with virtual functions contains a hidden virtual pointer (vptr), adding its size (usually 4 or 8 bytes) to the object.
Correct Answer: b) A hidden pointer added to objects of classes with virtual functions, pointing to the vtable
Explanation:
The vptr (virtual pointer) is inserted by the compiler to point to the virtual table (vtable) for dynamic dispatch.
Correct Answer: b) A static array of function pointers for virtual functions
Explanation:
The vtable (virtual table) is a static array created by the compiler for each class with virtual functions, storing pointers to the actual functions.
Correct Answer: b) During the constructor execution
Explanation:
The vptr is initialized by the compiler-generated code inside the constructor, before the user-defined constructor body executes.
Correct Answer: b) Yes, but it calls the base class version
Explanation:
When a virtual function is called from a base class constructor, the vptr points to the base class's vtable, so the base class version is executed.
Correct Answer: b) Preventing a class from being inherited or a virtual function from being overridden
Explanation:
The 'final' specifier prevents further derivation of a class or overriding of a virtual function in derived classes.
Correct Answer: b) Explicitly indicating that a function is intended to override a base class virtual function
Explanation:
The 'override' specifier ensures the function actually overrides a base class virtual function, catching signature mismatches at compile time.
Correct Answer: b) When a derived class object is assigned to a base class object, losing derived-specific data
Explanation:
Object slicing occurs when a derived object is passed by value to a base class parameter, truncating the derived part.
Correct Answer: a) Using pointers or references
Explanation:
Passing objects by pointer or reference prevents slicing because the original derived object is not copied into a base object.
Correct Answer: b) Preventing implicit conversions via single-argument constructors
Explanation:
The 'explicit' keyword prevents the compiler from using a single-argument constructor for implicit type conversions.
Correct Answer: a) Yes
Explanation:
Yes, a copy constructor can be explicit, which prevents implicit copying (e.g., passing by value without explicit casting).
Correct Answer: a) A constructor that calls another constructor in the same class
Explanation:
Delegating constructors allow one constructor to call another constructor of the same class to reuse initialization code.
Correct Answer: b) A function where the compiler attempts to embed the function body at the call site
Explanation:
Inline functions suggest to the compiler to replace the function call with the actual code to reduce function call overhead.
Correct Answer: b) No, it is a request to the compiler
Explanation:
The 'inline' keyword is a hint; the compiler may choose not to inline the function based on its complexity or other factors.
Correct Answer: b) 'delete' is for single objects, 'delete[]' is for arrays
Explanation:
'delete' calls the destructor for a single object, while 'delete[]' calls destructors for each element in an array.
Correct Answer: b) Undefined behavior, potentially missing destructor calls
Explanation:
Using 'delete' on an array results in undefined behavior, often leading to memory leaks because only the first object's destructor is called.
Correct Answer: b) A declarative region that provides a scope for identifiers
Explanation:
Namespaces are used to organize code into logical groups and prevent name collisions in large projects.
Correct Answer: a) namespace
Explanation:
The 'namespace' keyword is used to define a namespace, e.g., namespace MySpace { ... }.
Correct Answer: b) A way to bring all names from a namespace into the current scope
Explanation:
The 'using namespace' directive allows you to use names from a namespace without qualifying them.
Correct Answer: b) Bringing a specific name from a namespace into the current scope
Explanation:
A 'using' declaration brings a single specific identifier from a namespace into the current scope, e.g., using std::cout;
Correct Answer: a) std
Explanation:
The standard library components in C++ are defined within the 'std' namespace.
Correct Answer: a) Yes
Explanation:
Namespaces can be nested within other namespaces to create hierarchical scopes.
Correct Answer: a) A namespace with no name, giving internal linkage to its members
Explanation:
An unnamed namespace restricts the visibility of its members to the current translation unit, similar to 'static' in C.
Correct Answer: b) A namespace whose members are automatically available in the enclosing scope
Explanation:
An inline namespace allows its members to be used as if they were in the enclosing namespace, useful for versioning.
Correct Answer: b) A class should not define custom destructors, copy/move constructors, or assignment operators if possible
Explanation:
The Rule of Zero suggests relying on compiler-generated special member functions by using smart pointers and standard containers.
Correct Answer: b) If a class defines one of destructor, copy constructor, copy assignment, move constructor, or move assignment, it should probably define all five
Explanation:
The Rule of Five extends the Rule of Three to include move semantics introduced in C++11.
Correct Answer: b) A constructor that transfers resources from a temporary object
Explanation:
A move constructor takes an rvalue reference and transfers ownership of resources, avoiding expensive deep copies.
Correct Answer: b) A reference denoted by &&, typically binding to temporary objects
Explanation:
Rvalue references (&&) bind to temporary objects (rvalues) and enable move semantics.
Correct Answer: b) A utility that casts an lvalue to an rvalue reference
Explanation:
std::move does not actually move anything; it casts its argument to an rvalue reference, enabling move operations.
Correct Answer: a) Indicates a function does not throw exceptions
Explanation:
The 'noexcept' specifier tells the compiler that a function will not throw exceptions, allowing for optimizations.
Correct Answer: a) Yes, highly recommended
Explanation:
Marking move operations as noexcept is recommended because standard library containers may fall back to copying if moves can throw.
Correct Answer: b) A special member function explicitly requested to be generated by the compiler using = default
Explanation:
Using '= default' explicitly asks the compiler to generate the default implementation of a special member function.
Correct Answer: b) A function that is explicitly prohibited from being called using = delete
Explanation:
Using '= delete' prevents a function from being called, often used to disable copying or specific conversions.
Correct Answer: b) Delete the copy constructor and copy assignment operator
Explanation:
Deleting the copy constructor and copy assignment operator (= delete) explicitly prevents copying of the class.
Correct Answer: b) A class that has a trivial default constructor, copy/move constructors, and destructor
Explanation:
A trivial class has special member functions that perform no action, making it compatible with C-style memory operations like memcpy.
Correct Answer: a) A class with a specific memory layout compatible with C structs
Explanation:
Standard-layout classes have a memory layout that is compatible with C, allowing interoperability with C APIs.
Correct Answer: a) A class that is both trivial and standard-layout
Explanation:
POD types are trivial and standard-layout, meaning they behave like simple C structs and can be safely copied with memcpy.
Correct Answer: b) Inspects the declared type of an entity or the type and value category of an expression
Explanation:
'decltype' is used to deduce the exact type of an expression, including references and const qualifiers.
Correct Answer: b) Compiler deduces the type of a variable from its initializer
Explanation:
The 'auto' keyword allows the compiler to automatically deduce the type of a variable from its initialization expression.
Correct Answer: a) A new type created with 'typedef' or 'using'
Explanation:
Type aliases provide alternative names for existing types, improving code readability using 'typedef' or the 'using' keyword.
Correct Answer: b) using
Explanation:
The 'using' keyword is preferred over 'typedef' in modern C++ because it is clearer and supports templates (alias templates).
Correct Answer: b) A type alias for a template, defined using 'using'
Explanation:
Alias templates allow creating a shorthand name for a specific instantiation of a template, e.g., using MyVec = std::vector;
Correct Answer: a) Indicates a value or function can be evaluated at compile time
Explanation:
'constexpr' specifies that the value of a variable or the return value of a function can be computed at compile time.
Correct Answer: a) Yes
Explanation:
Member functions can be constexpr if they meet certain constraints, allowing objects to be constructed at compile time.
Correct Answer: a) Indicates a function must be evaluated at compile time
Explanation:
'consteval' specifies that every call to the function must produce a compile-time constant, unlike 'constexpr' which allows runtime evaluation.
Correct Answer: a) Indicates a variable must be initialized with a constant expression
Explanation:
'constinit' ensures a variable with static or thread-local storage duration is initialized with a constant expression, avoiding dynamic initialization.
Related Posts
New
NewNew

Latest C++ Basics MCQs
Created by Bjarne Stroustrup as an extension of the C programming language, C++ is a powerful, high-performance, statically typed language…
October 19, 2026By MCQs Generator
No Image
C++ Inheritance and Polymorphism - MCQs
1. Which keyword is used to define a class in C++? a) class b) struct c) object d) define Show…
October 19, 2026By MCQs Generator
No Image
400+ C++ Interview Questions MCQ
1. Which keyword is used to define a class in C++? a) class b) struct c) object d) define Show…
October 19, 2026By MCQs Generator








