Object Oriented Programming MCQs with Answers
Practice important Object Oriented Programming MCQs with answers and explanations.
Multiple Choice Questions
Q131: What is the result of using the statement `Student studentB = studentA;` if a copy constructor is not explicitly defined?
- A: The default copy constructor is used
- B: The compiler throws an error
- C: A deep copy is performed
- D: A shallow copy is performed
View Answer
A
Q132: Fill in the blank: Inline functions are typically _______ in size and called frequently.
- A: small
- B: large
- C: medium
- D: none of the above
View Answer
A
Q133: What does the `setRollNo` function in the `Student` class do?
- A: Sets the roll number of the student
- B: Displays the student's name
- C: Calculates the student's GPA
- D: None of the above
View Answer
A
Q134: What is a copy constructor used for in C++?
- A: Initializing an object with the state of a pre-existing object
- B: Performing arithmetic operations
- C: Creating new objects from scratch
- D: Deleting objects
View Answer
A
Q135: Which of the following is a correct syntax for a copy constructor?
- A: Student::Student(Student &obj) { ... }
- B: Student::Student(const Student &obj) { ... }
- C: Student::Student(Student obj) { ... }
- D: Student::Student(const Student obj) { ... }
View Answer
B
Q136: What does a shallow copy involve?
- A: Creating a new object with a new memory allocation for dynamic members
- B: Copying data members bit by bit to a new object
- C: Reinitializing an existing object
- D: Deleting an object
View Answer
B
Q137: In the context of copy constructors, what is the problem with shallow copying when dealing with dynamic memory?
- A: Dangling pointer issue
- B: Memory leak issue
- C: Buffer overflow issue
- D: None of the above
View Answer
A
Q138: What is the purpose of deep copying?
- A: To avoid issues with dangling pointers
- B: To create a new object with the same memory reference
- C: To speed up object creation
- D: To reduce memory usage
View Answer
A
Q139: Fill in the blank: Shallow copy performs a _____ copy of data members.
- A: bitwise
- B: deep
- C: dynamic
- D: shallow
View Answer
D
Q140: Fill in the blank: In a deep copy, a new dynamic memory allocation is made for the _____ members of a class.
- A: static
- B: public
- C: private
- D: dynamic
View Answer
D