Object Oriented Programming MCQs with Answers
Practice important Object Oriented Programming MCQs with answers and explanations.
Multiple Choice Questions
Q191: How can you access a member function of a dynamically allocated object?
- A: Using the dot operator (.)
- B: Using the arrow operator (->)
- C: Using the scope resolution operator (::)
- D: Using the address-of operator (&)
View Answer
B
Q192: What is the purpose of the delete operator in C++?
- A: To deallocate memory of dynamically allocated objects
- B: To initialize objects
- C: To create new objects
- D: To access static members
View Answer
A
Q193: What is the role of the new operator in object creation?
- A: Allocating space and calling the constructor
- B: Deallocating memory and calling the destructor
- C: Allocating space and calling the destructor
- D: Creating an object without constructor
View Answer
A
Q194: In the Date class, where is the defaultDate variable defined?
- A: Inside the class definition
- B: Inside the class constructor
- C: Outside the class definition
- D: Inside the class destructor
View Answer
C
Q195: What is the correct way to initialize a static member in a class?
- A: Inside the class definition
- B: Inside the class constructor
- C: Outside the class definition
- D: Inside the class destructor
View Answer
C
Q196: Which method is used to set the default date in the Date class?
- A: setDay
- B: setDefaultDate
- C: addDay
- D: setDate
View Answer
B
Q197: What is the purpose of the addYear function in the Date class?
- A: To increment the year by a specified number
- B: To set the default year
- C: To initialize the year
- D: To get the current year
View Answer
A
Q198: What is the return type of the getMonth method in the Date class?
- A: void
- B: int
- C: bool
- D: Date
View Answer
B
Q199: How is the leapYear function used in the Date class?
- A: To check if a year is a leap year
- B: To calculate the number of leap years
- C: To set the year as a leap year
- D: To add a leap year
View Answer
A
Q200: The Date class destructor is used to _______.
- A: Deallocate memory of Date objects
- B: Initialize Date objects
- C: Set default values for Date
- D: Add years to the Date
View Answer
A