Polymorphism in C++ MCQs Exercise II


Ques 1 Polymorphism


Can we overload functions in C++?
  a) True
  b) False
  c) Sometimes
  d) None of these


a is the correct option





Ques 2 Polymorphism


To enable runtime polymorphism in C++, the base class should have:
  a) Static member functions
  b) Friend functions
  c) Private member functions
  d) Virtual functions


d is the correct option





Ques 3 Polymorphism


In C++, can you create an object of an abstract class?
  a) Yes, you can create an object of an abstract class.
  b) No, you cannot create an object of an abstract class.
  c) Only if the abstract class contains a constructor.
  d) Only if the abstract class is a subclass of another non-abstract class.


b is the correct option





Ques 4 Polymorphism


Which keyword is used to declare a virtual function in C++?
  a) virtual
  b) polymorphic
  c) override
  d) base


a is the correct option





Ques 5 Polymorphism


When should the destructor of a base class be declared as virtual?
  a) When the base class contains pure virtual functions.
  b) When the base class is an abstract class.
  c) When the base class has derived classes and the base class pointers are used to delete derived class objects.
  d) Destructor of a base class should always be virtual.


c is the correct option





Ques 6 Polymorphism


What will be the output of the following C++ code?

#include<iostream>
class Base {
public:
    virtual void display() {
        std::cout << "Base" << std::endl;
    }
};
class Derived : public Base {
public:
    void display() override {
        std::cout << "Derived" << std::endl;
    }
};
int main() {
    Base* basePtr = new Derived;
    Derived derivedObj;
    basePtr->display();
    derivedObj.display();
    delete basePtr;
    return 0;
}

  a) Base Derived
  b) Derived Derived
  c) Base Base
  d) Derived Base


a is the correct option