Object Oriented Programming MCQs with Answers
Practice important Object Oriented Programming MCQs with answers and explanations.
Chapter: 27
Q441:
In specialization, can the derived class always replace the base class?
A. Yes
B. No
C. Sometimes
D. Only in private inheritance
Correct Answer:
B
Chapter: 27
Q442:
Which type of inheritance is used when the derived class is behaviorally incompatible with the base class?
A. Public
B. Protected
C. Private
D. All of the above
Correct Answer:
C
Chapter: 27
Q443:
When using private inheritance, what happens to the public and protected members of the base class?
A. They remain public and protected in the derived class
B. They become private members of the derived class
C. They are hidden from the derived class
D. They are deleted
Correct Answer:
B
Chapter: 27
Q444:
Which of the following is a correct characteristic of protected inheritance?
A. Derived class members and friends can access base class members
B. Only derived class can access base class members
C. Derived class friends only can access base class members
D. Public can access base class members
Correct Answer:
A
Chapter: 27
Q445:
Which constructor is called first in the object construction process in inheritance?
A. Derived class constructor
B. Friend class constructor
C. Base class constructor
D. All constructors are called simultaneously
Correct Answer:
C
Chapter: 27
Q446:
In the provided example, why does the line Parent *pptr = & cobj; result in an error?
A. Because of incorrect syntax
B. Because Child is privately inherited from Parent
C. Because Parent is not defined
D. Because of protected inheritance
Correct Answer:
B
Chapter: 27
Q447:
In private inheritance, which class in the hierarchy cannot access the member functions of the GrandParent class?
A. Parent
B. Derived class one level down
C. Derived class more than one level down
D. Any class outside the hierarchy
Correct Answer:
C
Chapter: 27
Q448:
Fill in the blank: __________ inheritance is used to implement specialization.
A. Public
B. Protected
C. Private
D. Hybrid
Correct Answer:
C
Chapter: 27
Q449:
What type of inheritance allows the derived class to access only the protected and public members of the base class?
A. Private
B. Protected
C. Public
D. Hybrid
Correct Answer:
B
Chapter: 27
Q450:
Which function is NOT allowed to be accessed by the Set class in the provided example?
A. AddElement
B. IsMember
C. DeleteMember
D. SearchElement
Correct Answer:
D
Chapter: 27
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
Correct Answer:
C
Chapter: 27
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
Correct Answer:
C
Chapter: 27
Q453:
Which keyword is used to represent protected inheritance in C++?
A. public
B. private
C. protected
D. inherited
Correct Answer:
C
Chapter: 28
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.
Correct Answer:
B
Chapter: 28
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.
Correct Answer:
B
Chapter: 28
Q456:
Which function in C++ is used to achieve dynamic binding?
A. Static function
B. Virtual function
C. Friend function
D. Inline function
Correct Answer:
B
Chapter: 28
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
Correct Answer:
C
Chapter: 28
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
Correct Answer:
C
Chapter: 28
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
Correct Answer:
C
Chapter: 28
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
Correct Answer:
C