Object Oriented Programming MCQs with Answers
Practice important Object Oriented Programming MCQs with answers and explanations.
Multiple Choice Questions
Q371: What is static typing?
- A: A dynamic type system
- B: The type used to declare a reference or pointer
- C: Runtime type identification
- D: A debugging method
View Answer
B
Q372: What happens if you try to access derived class methods using a base class reference?
- A: The method is called
- B: The program crashes
- C: The compiler generates an error
- D: The method is ignored
View Answer
C
Q373: How can a function parameter of a base class type be initialized?
- A: Only with a base class object
- B: With a derived class object
- C: With any object
- D: It cannot be initialized
View Answer
B
Q374: What will the following code output? cout << pPtr->GetRollNo(); where pPtr is of type Person*.
- A: The roll number
- B: A compile-time error
- C: Undefined behavior
- D: Nothing
View Answer
B
Q375: What is the main purpose of protected members in a class?
- A: To allow access only within the class
- B: To allow access from derived classes
- C: To allow access from anywhere
- D: To prevent any access
View Answer
B
Q376: In C++, public inheritance represents which type of relationship between classes?
- A: HAS-A
- B: IS-A
- C: USES-A
- D: PART-OF
View Answer
B
Q377: Which access specifier allows derived classes to access base class members but denies access to other classes?
- A: Public
- B: Private
- C: Protected
- D: Friend
View Answer
C
Q378: What is the issue with using shallow copy in classes that utilize dynamic memory allocation?
- A: It copies all data correctly
- B: It leads to duplicate memory allocation
- C: Both objects share the same memory location
- D: It is faster than deep copy
View Answer
C
Q379: How do you explicitly call a base class copy constructor in a derived class?
- A: By using the 'super' keyword
- B: By calling it in the derived class constructor's body
- C: By using base class name in the initialization list
- D: It is called automatically
View Answer
C
Q380: What happens if you do not explicitly call the base class copy constructor in a derived class copy constructor?
- A: Base class copy constructor is called automatically
- B: Base class default constructor is called
- C: Base class constructor is not called
- D: Program will not compile
View Answer
B