PRACTICE • LEARN • GROW
Module 5 Final Quiz: Object-Oriented Programming MCQs
Solve topic-wise placement questions and improve your skills.
Module 5 Final Quiz: Object-Oriented Programming Progress
0 of 12 completed
0%
Topic Track
You are viewing MCQs in preview mode. Log in to select options, submit answers, and track your progress.
Log In to Answer
1
What is the difference between a class and an object in C++?
A.
A class is an instance in memory; an object is the source code
B.
A class is an abstract blueprint defining structure and behavior; an object is a concrete instance of that class in memory
C.
They are completely interchangeable terms with no difference
D.
Classes are only used in Java, while objects are only used in C++
Explanation & Key
Correct Answer:
2
When does a class destructor execute?
A.
When the object is instantiated
B.
When the object is destroyed (goes out of scope or is deleted)
C.
When an exception is caught
D.
Every time a member function is called
Explanation & Key
Correct Answer:
3
What is Encapsulation in C++ and how is it achieved?
A.
Making all member variables public so any function can edit them
B.
Bundling data and methods together while marking internal data members private, exposing controlled access via public getters/setters
C.
Inheriting from multiple base classes simultaneously
D.
Compiling code into a dynamic link library (.dll)
Explanation & Key
Correct Answer:
4
What relationship does public inheritance model in C++ (e.g. class Dog : public Animal)?
A.
A 'has-a' composition relationship
B.
An 'is-a' relationship (a Dog is an Animal)
C.
A 'uses-a' dependency relationship
D.
A friend relationship
Explanation & Key
Correct Answer:
5
What keyword must be applied to a base-class member function to enable runtime dynamic polymorphism?
A.
static
B.
inline
C.
virtual
D.
friend
Explanation & Key
Correct Answer:
6
What is a Pure Virtual Function in C++?
A.
A function that has no parameters
B.
A virtual function declared with '= 0' that has no implementation in the base class, making the class abstract
C.
A function written in assembly language
D.
A function that can only be called once
Explanation & Key
Correct Answer:
7
What is the output of the following polymorphic code snippet?
class Animal {
public:
virtual void speak() { cout << "A"; }
};
class Dog : public Animal {
public:
void speak() override { cout << "D"; }
};
Animal* a = new Dog();
a->speak();
A.
A
B.
D
C.
AD
D.
Compilation Error
Explanation & Key
Correct Answer:
8
What is the purpose of the 'override' specifier in derived class virtual functions (C++11)?
A.
It makes the function run faster
B.
It instructs the compiler to verify that a base-class virtual function with the exact same signature exists, preventing subtle mismatch bugs
C.
It allows private inheritance to become public
D.
It forces the function to be inline
Explanation & Key
Correct Answer:
9
Why should a base class intended for polymorphic deletion always declare a virtual destructor?
A.
Otherwise the derived class destructor will not be called when deleting through a base pointer, causing resource leaks and undefined behavior
B.
It is required for templates to compile
C.
It makes the object allocate on the stack instead of heap
D.
Destructors cannot be virtual in C++
Explanation & Key
Correct Answer:
10
How do you overload the '+' operator for a custom class Point?
A.
Point add(Point a, Point b)
B.
Point operator+(const Point& p)
C.
void operator_plus(Point p)
D.
operator.plus(Point p)
Explanation & Key
Correct Answer:
11
What is the default access specifier for members of a C++ class if none is specified?
A.
public
B.
protected
C.
private
D.
internal
Explanation & Key
Correct Answer:
12
What is the purpose of an initializer list in a constructor (e.g. MyClass(int v) : val(v) {})?
A.
It initializes member variables directly before the constructor body executes, avoiding redundant default construction
B.
It prints values to the console
C.
It prevents memory allocation
D.
It converts integers to floats
Explanation & Key
Correct Answer:
Question Palette
Answered
Current
Not Attempted
Wrong