Skip to main content

Object Oriented Programming MCQs with Answers

Practice important Object Oriented Programming MCQs with answers and explanations.

Multiple Choice Questions

Q381: Which casting operator is used for converting pointers or references within an inheritance hierarchy safely?
  • A: static_cast
  • B: dynamic_cast
  • C: reinterpret_cast
  • D: const_cast
View Answer
B

Q382: In C++, what is 'upcasting'?
  • A: Converting base class pointer to derived class pointer
  • B: Converting derived class pointer to base class pointer
  • C: Converting between unrelated types
  • D: Converting pointers to void pointers
View Answer
B

Q383: What is the correct syntax for performing a static_cast in C++?
  • A: static_cast(expression)
  • B: cast_static(expression)
  • C: static_cast(expression)
  • D: static_cast(type, expression)
View Answer
A

Q384: Which C++ cast would you use to remove the constness of a variable?
  • A: static_cast
  • B: dynamic_cast
  • C: const_cast
  • D: reinterpret_cast
View Answer
C

Q385: When copying an object that contains pointers, which method ensures each object has its own copy of the data?
  • A: Shallow copy
  • B: Deep copy
  • C: Default copy
  • D: Reference copy
View Answer
B

Q386: In the context of inheritance, what does the following code do? static_cast<Person&>(*this) = rhs;
  • A: Performs an explicit call to base class assignment operator
  • B: Calls derived class assignment operator
  • C: Causes a runtime error
  • D: Converts 'this' to a pointer
View Answer
A

Q387: What is the outcome if a derived class destructor is not defined but the base class destructor is defined?
  • A: Base class destructor is not called
  • B: Derived class destructor is called automatically
  • C: Only base class destructor is called
  • D: Program crashes
View Answer
C

Q388: Which cast should be used when you need to cast a pointer to an unrelated type?
  • A: static_cast
  • B: dynamic_cast
  • C: reinterpret_cast
  • D: const_cast
View Answer
C

Q389: In the provided example, what is the effect of not calling the base class assignment operator in the derived class?
  • A: Base class members are copied correctly
  • B: Base class members are not copied
  • C: Causes a compile-time error
  • D: Causes a runtime error
View Answer
B

Q390: How can you prevent the compiler from generating a default copy constructor?
  • A: Declare a private copy constructor
  • B: Declare a public copy constructor
  • C: Use 'delete' keyword with copy constructor
  • D: Do not define any constructors
View Answer
C

Test Your Knowledge

Take a timed quiz on Object Oriented Programming

🚀 Start Quiz Now