Skip to main content

Object Oriented Programming MCQs with Answers

Practice important Object Oriented Programming MCQs with answers and explanations.

Chapter: 13
Q201:
The setDay method of the Date class accepts a day value and _______.
A. Sets it as a default day
B. Checks if it is a valid day
C. Adds it to the current day
D. Initializes the day to zero
Correct Answer: B
Chapter: 13
Q202:
In the Date class, the setDate method does what?
A. Sets the day, month, and year to default
B. Sets the day, month, and year and displays the date
C. Adds days, months, and years to the current date
D. Deletes the Date object
Correct Answer: B
Chapter: 13
Q203:
The Date class uses a static member to store _______.
A. The default date
B. The current date
C. The number of Date objects
D. The day of the month
Correct Answer: A
Chapter: 13
Q204:
A class with an array of objects must have a _______ if an explicit initializer is not provided.
A. Default constructor
B. Destructor
C. Static member
D. Static function
Correct Answer: A
Chapter: 13
Q205:
The main function in the provided code creates a Date object with default values using _______.
A. Date aDate(0, 0, 0);
B. Date aDate;
C. Date aDate(20, 10, 2011);
D. Date aDate = Date();
Correct Answer: A
Chapter: 13
Q206:
Static member functions can access _______ members of the class.
A. Static
B. Non-static
C. Private
D. Protected
Correct Answer: A
Chapter: 13
Q207:
A static member variable in a class is initialized _______.
A. Inside the class definition
B. In the class constructor
C. Outside the class definition
D. In the class destructor
Correct Answer: C
Chapter: 13
Q208:
The Date class destructor prints _______ when a Date object is destroyed.
A. "Date destructor"
B. "Object destroyed"
C. "Date deleted"
D. "Destructor invoked"
Correct Answer: A
Chapter: 13
Q209:
The Date class uses the leapYear function to _______.
A. Determine if the year is a leap year
B. Calculate the number of leap years
C. Set the year as a leap year
D. Add leap days to the year
Correct Answer: A
Chapter: 13
Q210:
The setDefaultDate method in the Date class is used to _______.
A. Set the default date for all Date objects
B. Update the date of a specific object
C. Delete the default date
D. Set the day, month, and year of a new object
Correct Answer: A
Chapter: 13
Q211:
To create an array of Date objects, you need _______ constructor.
A. Default constructor
B. Destructor
C. Copy constructor
D. Static constructor
Correct Answer: A
Chapter: 13
Q212:
The setMonth method in the Date class validates the month to be between _______ and _______.
A. 0 and 12
B. 1 and 12
C. 1 and 31
D. 0 and 31
Correct Answer: B
Chapter: 13
Q213:
A static member function in the Date class _______ non-static members.
A. Cannot access
B. Can modify
C. Can access directly
D. Can access indirectly
Correct Answer: A
Chapter: 13
Q214:
The addDay method in the Date class adds _______ to the current day.
A. A specified number of days
B. A specified number of months
C. A specified number of years
D. The default number of days
Correct Answer: A
Chapter: 13
Q215:
To allocate memory for an array of Student objects, you use _______.
A. new Student[100]
B. malloc(100 * sizeof(Student))
C. new Student()
D. new Student
Correct Answer: A
Chapter: 14
Q216:
In object-oriented programming, what does composition imply about the relationship between objects?
A. One object inherits from another
B. One object contains another object
C. One object executes methods of another
D. One object replaces another
Correct Answer: B
Chapter: 14
Q217:
When using dynamic memory allocation for a class member in C++, what operator is used to allocate memory?
A. delete
B. new
C. free
D. allocate
Correct Answer: B
Chapter: 14
Q218:
Which of the following is a correct way to allocate an array of objects using the new operator in C++?
A. Student *ptr = new Student[100];
B. Student ptr = new Student[100];
C. Student *ptr = new Student(100);
D. Student ptr = new Student(100);
Correct Answer: A
Chapter: 14
Q219:
In the Student class, what function is used to initialize a new student's name?
A. SetName()
B. GetName()
C. SetRollNo()
D. GetRollNo()
Correct Answer: A
Chapter: 14
Q220:
What does the destructor in the Student class do?
A. Allocates memory for the name variable
B. Deletes the memory allocated for the name variable
C. Initializes the name variable
D. Changes the roll number
Correct Answer: B

Test Your Knowledge

Take a timed quiz on Object Oriented Programming

🚀 Start Quiz Now