Skip to main content

Object Oriented Programming MCQs with Answers

Practice important Object Oriented Programming MCQs with answers and explanations.

Chapter: 12
Q181:
How can you access non-static members from a static member function?
A. Directly within the static member function
B. Through an instance of the class
C. By using the this pointer
D. It is not possible
Correct Answer: D
Chapter: 12
Q182:
What is the purpose of using a this pointer in non-static member functions?
A. To access static members
B. To access non-static members
C. To call other static functions
D. To modify static data members
Correct Answer: B
Chapter: 12
Q183:
How do static data members differ from global variables?
A. Static members are local to the class
B. Global variables are more encapsulated
C. Static members can be accessed anywhere in the program
D. Global variables have limited scope compared to static members
Correct Answer: A
Chapter: 12
Q184:
Which of the following statements about static data members is correct?
A. They are allocated memory separately for each object
B. They are initialized each time a new object is created
C. They remain in memory even when all objects are destroyed
D. They can be accessed only through instance methods
Correct Answer: C
Chapter: 12
Q185:
What error occurs if you try to create an array of objects without a default constructor?
A. Compilation error
B. Runtime error
C. Logical error
D. No error
Correct Answer: A
Chapter: 12
Q186:
In the Student class example, what is the result of calling Student::getTotalStudents() if it accesses noOfStudents?
A. Returns the number of students
B. Causes a compilation error
C. Returns 0
D. Returns a random value
Correct Answer: A
Chapter: 12
Q187:
What happens if you access a static data member using a non-static method?
A. It is not possible
B. It will compile but not work
C. It will access the static member correctly
D. It will throw a runtime error
Correct Answer: C
Chapter: 13
Q188:
What is a pointer to an object in C++?
A. A pointer that points to built-in types
B. A pointer that points to other pointers
C. A pointer that points to a class object
D. A pointer that points to a function
Correct Answer: C
Chapter: 13
Q189:
How can you dynamically allocate an object in C++?
A. Using the malloc function
B. Using the new operator
C. Using the calloc function
D. Using the delete operator
Correct Answer: B
Chapter: 13
Q190:
What happens when you use new Student in C++?
A. It creates an object on the stack
B. It creates an object on the heap
C. It creates a global object
D. It creates an array of objects
Correct Answer: B
Chapter: 13
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 (&)
Correct Answer: B
Chapter: 13
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
Correct Answer: A
Chapter: 13
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
Correct Answer: A
Chapter: 13
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
Correct Answer: C
Chapter: 13
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
Correct Answer: C
Chapter: 13
Q196:
Which method is used to set the default date in the Date class?
A. setDay
B. setDefaultDate
C. addDay
D. setDate
Correct Answer: B
Chapter: 13
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
Correct Answer: A
Chapter: 13
Q198:
What is the return type of the getMonth method in the Date class?
A. void
B. int
C. bool
D. Date
Correct Answer: B
Chapter: 13
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
Correct Answer: A
Chapter: 13
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
Correct Answer: A

Test Your Knowledge

Take a timed quiz on Object Oriented Programming

🚀 Start Quiz Now