Ques 1 Polymorphism
Can we overload functions in C++?
a) True
b) False
c) Sometimes
d) None of these
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
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.
Ques 4 Polymorphism
Which keyword is used to declare a virtual function in C++?
a) virtual
b) polymorphic
c) override
d) base
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.
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; }