Skip to main content

Object Oriented Programming MCQs with Answers

Practice important Object Oriented Programming MCQs with answers and explanations.

Chapter: 9
Q141:
What should you do in a destructor to prevent memory leaks?
A. Free the memory allocated using new
B. Reallocate memory
C. Call the copy constructor
D. Perform no action
Correct Answer: A
Chapter: 9
Q142:
Which of the following is not true about the this pointer?
A. It is a pointer to the current object
B. It is automatically passed to member functions
C. It can be used to access static members
D. It helps in differentiating between member variables and parameters
Correct Answer: C
Chapter: 9
Q143:
What does the setRollNo function do in the given example?
A. It sets the roll number with error checking
B. It retrieves the roll number
C. It deletes the roll number
D. It prints the roll number
Correct Answer: A
Chapter: 9
Q144:
Fill in the blank: The ~Student function in a class is known as the _____ function.
A. destructor
B. constructor
C. accessor
D. mutator
Correct Answer: A
Chapter: 9
Q145:
What will happen if you delete an object with dynamic memory without proper deep copying?
A. The memory allocated for dynamic members may be freed and lead to dangling pointers
B. The object will be recreated
C. The memory will be reallocated automatically
D. Nothing, as it does not affect dynamic memory
Correct Answer: A
Chapter: 9
Q146:
Fill in the blank: The copy constructor is called when an object is _____ to another object.
A. assigned
B. initialized
C. deleted
D. copied
Correct Answer: D
Chapter: 9
Q147:
What is an important point to remember about copy constructors?
A. They perform deep copying when dynamic memory is involved
B. They perform shallow copying always
C. They do not affect memory management
D. They are not necessary for classes with dynamic memory
Correct Answer: A
Chapter: 10
Q148:
What is the purpose of the this pointer in C++?
A. Return the address of the class
B. Return reference to the current object
C. Return reference to a static object
D. Return the address of a method
Correct Answer: B
Chapter: 10
Q149:
Which method can be used to implement method chaining in C++?
A. Using const keyword
B. Using this pointer
C. Using static methods
D. Using virtual methods
Correct Answer: B
Chapter: 10
Q150:
What does return *this; in a member function indicate?
A. Returning the address of the current object
B. Returning a copy of the current object
C. Returning a reference to the current object
D. Returning a pointer to the method
Correct Answer: C
Chapter: 10
Q151:
Separation of interface and implementation in C++ is primarily achieved through which files?
A. .h and .cpp files
B. .cpp and .exe files
C. .h and .lib files
D. .cpp and .obj files
Correct Answer: A
Chapter: 10
Q152:
In which form is the modulus of a complex number denoted?
A. Phasor form
B. Euler form
C. Cartesian form
D. Polar form
Correct Answer: B
Chapter: 10
Q153:
What is the purpose of const keyword in member functions?
A. To allow modification of the class state
B. To prevent modification of the class state
C. To make a function virtual
D. To declare a function as static
Correct Answer: B
Chapter: 10
Q154:
If a class has dynamic memory allocation, shallow copy will likely lead to which problem?
A. Memory leak
B. Dangling pointer
C. Redundant memory usage
D. Stack overflow
Correct Answer: B
Chapter: 10
Q155:
The setNumber method in the new implementation of the Complex class uses which form of complex number?
A. Euler form
B. Phasor form
C. Cartesian form
D. Polar form
Correct Answer: B
Chapter: 10
Q156:
What is the main benefit of separating interface from implementation in C++?
A. Easier to manage memory
B. Improved software engineering
C. Faster execution of code
D. Reduced code size
Correct Answer: B
Chapter: 10
Q157:
What kind of copy does the default copy constructor perform?
A. Deep copy
B. Shallow copy
C. Bitwise copy
D. Logical copy
Correct Answer: B
Chapter: 10
Q158:
In the context of C++ classes, which file typically contains the class's interface?
A. .cpp file
B. .exe file
C. .h file
D. .lib file
Correct Answer: C
Chapter: 11
Q159:
What issue arises when trying to assign a value to a constant data member in a constructor?
A. Value assignment is allowed
B. Compiler generates an error
C. Value assignment is ignored
D. Compiler generates a warning
Correct Answer: B
Chapter: 11
Q160:
What is the purpose of a member initializer list in C++?
A. To initialize data members before constructor execution
B. To assign values after constructor execution
C. To define class member variables
D. To declare member functions
Correct Answer: A

Test Your Knowledge

Take a timed quiz on Object Oriented Programming

🚀 Start Quiz Now