Skip to main content

Object Oriented Programming MCQs with Answers

Practice important Object Oriented Programming MCQs with answers and explanations.

Chapter: 24
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
Correct Answer: B
Chapter: 24
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
Correct Answer: B
Chapter: 24
Q383:
What is the correct syntax for performing a static_cast in C++?
A. static_cast<type>(expression)
B. cast_static<type>(expression)
C. static_cast(expression)<type>
D. static_cast(type, expression)
Correct Answer: A
Chapter: 24
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
Correct Answer: C
Chapter: 24
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
Correct Answer: B
Chapter: 24
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
Correct Answer: A
Chapter: 24
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
Correct Answer: C
Chapter: 24
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
Correct Answer: C
Chapter: 24
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
Correct Answer: B
Chapter: 24
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
Correct Answer: C
Chapter: 24
Q391:
What does the following code snippet demonstrate? Person::GetName() within Student::Print()
A. Implicit call to base class method
B. Explicit call to base class method
C. Overriding base class method
D. Hiding base class method
Correct Answer: B
Chapter: 24
Q392:
When is a copy constructor called?
A. When an object is assigned to another existing object
B. When an object goes out of scope
C. When a new object is created from an existing object
D. When an object is deleted
Correct Answer: C
Chapter: 24
Q393:
What is the correct order of constructor calls when creating an object of a derived class?
A. Derived class constructor first, then base class constructor
B. Base class constructor first, then derived class constructor
C. Random order
D. Only derived class constructor is called
Correct Answer: B
Chapter: 24
Q394:
In the context of inheritance, which member function is responsible for cleaning up dynamic memory?
A. Constructor
B. Destructor
C. Copy constructor
D. Assignment operator
Correct Answer: B
Chapter: 24
Q395:
What does 'deep copy' mean in the context of object copying?
A. Copying only primitive data members
B. Copying all data members including dynamically allocated memory
C. Copying object address
D. Copying object methods only
Correct Answer: B
Chapter: 24
Q396:
Which C++ feature allows derived class objects to be treated as base class objects?
A. Polymorphism
B. Encapsulation
C. Abstraction
D. Inheritance
Correct Answer: D
Chapter: 24
Q397:
In the example provided, what is the result of assigning sobj1 to sobj2 without a user-defined assignment operator?
A. Shallow copy occurs
B. Deep copy occurs
C. Compile-time error
D. Runtime error
Correct Answer: A
Chapter: 24
Q398:
What is the purpose of the const keyword at the end of member function declarations?
A. To prevent the function from modifying class members
B. To make the function public
C. To allow function overloading
D. To make the function static
Correct Answer: A
Chapter: 24
Q399:
In C++, what does the following statement do? Derived* derived = dynamic_cast<Derived*>(base);
A. Converts base class pointer to derived class pointer safely
B. Converts derived class pointer to base class pointer
C. Performs a compile-time check
D. Causes a compile-time error
Correct Answer: A
Chapter: 24
Q400:
What will happen if you attempt to downcast using static_cast and the types are not compatible?
A. Safe conversion occurs
B. Compile-time error
C. Undefined behavior
D. The program crashes
Correct Answer: C

Test Your Knowledge

Take a timed quiz on Object Oriented Programming

🚀 Start Quiz Now