Object Oriented Programming MCQs with Answers
Practice important Object Oriented Programming MCQs with answers and explanations.
Multiple Choice Questions
Q451: What happens to private data members of the base class in any type of inheritance?
- A: They are accessible in all derived classes
- B: They become public in derived classes
- C: They are hidden and not accessible in derived classes
- D: They become protected in derived classes
View Answer
C
Q452: In which inheritance type is the base class interface made inaccessible from the outside world?
- A: Public
- B: Protected
- C: Private
- D: Multiple inheritance
View Answer
C
Q453: Which keyword is used to represent protected inheritance in C++?
- A: public
- B: private
- C: protected
- D: inherited
View Answer
C
Q454: What is the main problem with the code when trying to draw different shapes?
- A: The draw method is not defined in the derived classes.
- B: The draw method in Shape class is not virtual.
- C: The array does not store derived class objects.
- D: The drawShapes function is not properly defined.
View Answer
B
Q455: How does the concept of polymorphism benefit the shape hierarchy implementation?
- A: By ensuring compile-time type checking.
- B: By making sure each shape draws itself correctly without needing to know the specific type.
- C: By requiring separate draw methods for each shape.
- D: By simplifying the class structure.
View Answer
B
Q456: Which function in C++ is used to achieve dynamic binding?
- A: Static function
- B: Virtual function
- C: Friend function
- D: Inline function
View Answer
B
Q457: What type of relationship exists between the Shape class and the Line, Circle, and Triangle classes?
- A: HAS-A
- B: CAN-BE
- C: IS-A
- D: USES-A
View Answer
C
Q458: When the draw method in the Shape class is not virtual, which draw method is called?
- A: Line::draw
- B: Circle::draw
- C: Shape::draw
- D: Triangle::draw
View Answer
C
Q459: How can the problem of calling the wrong draw method in the shape hierarchy be solved?
- A: By using dynamic_cast
- B: By using if-else logic
- C: By making the draw method in Shape class virtual
- D: By using templates
View Answer
C
Q460: Which method of determining the type of shape was shown to be complex and error-prone?
- A: Using virtual functions
- B: Using templates
- C: Using switch or if-else logic
- D: Using polymorphism
View Answer
C