Skip to main content

Object Oriented Programming MCQs with Answers

Practice important Object Oriented Programming MCQs with answers and explanations.

Chapter: 28
Q461:
What does static binding mean in C++?
A. The target function for a call is selected at runtime.
B. The target function for a call is selected at compile time.
C. The function cannot be overridden.
D. The function is determined based on user input.
Correct Answer: B
Chapter: 28
Q462:
Fill in the blank: In C++, dynamic binding is achieved through the use of ________ functions.
A. friend
B. static
C. virtual
D. inline
Correct Answer: C
Chapter: 28
Q463:
What is the purpose of the calcArea method in the shape hierarchy?
A. To calculate the area of shapes.
B. To draw the shape.
C. To determine the type of shape.
D. To store the shape's dimensions.
Correct Answer: A
Chapter: 28
Q464:
Which of the following is NOT a derived class of Shape in the provided hierarchy?
A. Rectangle
B. Line
C. Circle
D. Triangle
Correct Answer: A
Chapter: 28
Q465:
Why is delocalized code considered problematic in the shape hierarchy implementation?
A. It simplifies code readability.
B. It causes redundant code in multiple places, leading to potential errors.
C. It increases the efficiency of the program.
D. It makes the code easier to maintain.
Correct Answer: B
Chapter: 28
Q466:
What output would you expect if the draw method in Shape class is not virtual and you try to draw a Circle stored in a Shape pointer array?
A. "Circle"
B. "Shape"
C. "Line"
D. "Triangle"
Correct Answer: B
Chapter: 29
Q467:
What is the main concept of Polymorphism?
A. The ability to use the same method name for different objects
B. The ability to inherit multiple classes
C. The ability to override methods in derived classes
D. The ability to instantiate abstract classes
Correct Answer: A
Chapter: 29
Q468:
What is an Abstract Class?
A. A class with no methods
B. A class that cannot be instantiated directly
C. A class that contains only public methods
D. A class that inherits from multiple base classes
Correct Answer: B
Chapter: 29
Q469:
How do you declare a Pure Virtual Function in C++?
A. virtual void functionName() = 0;
B. virtual void functionName() { }
C. virtual void functionName();
D. virtual void functionName() = 1;
Correct Answer: A
Chapter: 29
Q470:
Which of the following statements is true about Virtual Destructors?
A. A base class destructor must be made virtual to avoid memory leaks when deleting derived class objects.
B. The destructor of derived classes is always called before the base class destructor.
C. Derived class destructors must be declared as pure virtual functions.
D. A base class destructor must be private to avoid memory leaks.
Correct Answer: A
Chapter: 29
Q471:
If a class has at least one pure virtual function, it is known as:
A. A Concrete Class
B. A Virtual Class
C. A Derived Class
D. An Abstract Class
Correct Answer: D
Chapter: 29
Q472:
Fill in the blank: A class with no implementation for some methods is referred to as a(n) ______ class.
A. Concrete
B. Abstract
C. Derived
D. Static
Correct Answer: B
Chapter: 29
Q473:
Which of the following classes is abstract?
A. class Shape { public: virtual void draw() = 0; };
B. class Rectangle { public: void draw() { } };
C. class Quadrilateral { public: void draw() { } };
D. class Circle { public: void draw() { } };
Correct Answer: A
Chapter: 29
Q474:
When using virtual functions, which of the following is true?
A. The compiler generates code to access the vTable.
B. The vTable contains pointers to all functions in a class.
C. The base class pointer can only point to base class objects.
D. The derived class must have a non-virtual destructor.
Correct Answer: A
Chapter: 29
Q475:
In the context of virtual functions, what is Dynamic Dispatch?
A. Accessing the appropriate function at runtime using the vTable
B. Calling the function directly based on the class type
C. Accessing the function's implementation at compile time
D. Binding functions to their addresses at compile time
Correct Answer: A
Chapter: 29
Q476:
Which of the following scenarios will lead to a compiler error?
A. Creating an instance of a class with pure virtual functions.
B. Calling a virtual function from a base class pointer.
C. Overriding a pure virtual function in a derived class.
D. Using a derived class object to call a base class method.
Correct Answer: A
Chapter: 29
Q477:
What will happen if you delete a base class pointer that points to a derived class object without making the base class destructor virtual?
A. The derived class destructor will be called.
B. Only the base class part of the object will be deleted.
C. Memory leaks will be avoided.
D. The derived class object will be deleted correctly.
Correct Answer: B
Chapter: 29
Q478:
Fill in the blank: When a class's virtual function is overridden, the derived class will use its own version of the function, while the base class's version is ______.
A. Overridden
B. Shadowed
C. Called
D. Unchanged
Correct Answer: B
Chapter: 29
Q479:
What is the purpose of making a destructor virtual in a base class?
A. To ensure that derived class destructors are called when deleting a base class pointer.
B. To prevent base class destructors from being called.
C. To allow the base class destructor to access derived class methods.
D. To avoid having a destructor in the derived classes.
Correct Answer: A
Chapter: 29
Q480:
Which of the following best describes the use of pure virtual functions in C++?
A. They allow a class to provide a default implementation for derived classes.
B. They force derived classes to provide their own implementation of the function.
C. They are used to define static functions that cannot be overridden.
D. They enable classes to be instantiated directly.
Correct Answer: B

Test Your Knowledge

Take a timed quiz on Object Oriented Programming

🚀 Start Quiz Now