Object Oriented Programming MCQs with Answers
Practice important Object Oriented Programming MCQs with answers and explanations.
Multiple Choice Questions
Q401: Which casting operator should be used to check the validity of a downcast at runtime?
- A: static_cast
- B: dynamic_cast
- C: reinterpret_cast
- D: const_cast
View Answer
B
Q402: In the provided example, which method is used to cast 'this' pointer to base class reference implicitly?
- A: static_cast
- B: dynamic_cast
- C: C-style cast (Person)*this
- D: const_cast
View Answer
A
Q403: What is the main difference between copy constructor and assignment operator?
- A: Copy constructor initializes new objects; assignment operator copies values to existing objects
- B: Both do the same thing
- C: Assignment operator initializes new objects; copy constructor copies values
- D: There is no difference
View Answer
A
Q404: When overloading the assignment operator in derived classes, why is it necessary to call the base class assignment operator?
- A: To ensure base class members are properly copied
- B: It is not necessary
- C: To improve performance
- D: To prevent compilation errors
View Answer
A
Q405: What does the reinterpret_cast operator do in C++?
- A: Converts between related types safely
- B: Converts between unrelated types without safety checks
- C: Removes constness from variables
- D: Performs runtime type checking
View Answer
B
Q406: In the context of inheritance, what is 'downcasting'?
- A: Casting from base class to derived class
- B: Casting from derived class to base class
- C: Casting between unrelated classes
- D: Casting to void pointers
View Answer
A
Q407: Which casting operator would you use to convert a const int* to an int*?
- A: static_cast
- B: const_cast
- C: dynamic_cast
- D: reinterpret_cast
View Answer
B
Q408: What is the result of this code snippet? Person* p = new Student();
- A: Compilation error
- B: p points to a Person object
- C: p points to a Student object treated as Person
- D: Runtime error
View Answer
C
Q409: In object-oriented programming, which principle is violated by using protected members extensively?
- A: Encapsulation
- B: Inheritance
- C: Polymorphism
- D: Abstraction
View Answer
A
Q410: What does the following code do? Person* p = static_cast<Person*>(&studentObj);
- A: Upcasts studentObj to Person pointer
- B: Downcasts studentObj to Person pointer
- C: Causes a compile-time error
- D: Performs runtime type check
View Answer
A