Ques 1 Polymorphism
What is polymorphism in C++?
Ques 2 Polymorphism
Which type of polymorphism is achieved through function overloading in C++?
Ques 3 Polymorphism
What is dynamic polymorphism in C++?
Ques 4 Polymorphism
What will be the output of the following C++ code?
#include<iostream> class Animal { public: virtual void makeSound() const { std::cout << "Generic animal sound" << std::endl; } }; class Dog : public Animal { public: void makeSound() const override { std::cout << "Woof Woof!" << std::endl; } }; int main() { Animal* animal = new Dog(); animal->makeSound(); delete animal; return 0; }
Ques 5 Polymorphism
What will be the output of the following C++ code?
#include<iostream> class Shape { public: virtual void draw() const { std::cout << "Drawing a Shape" << std::endl; } }; class Circle : public Shape { public: void draw() const override { std::cout << "Drawing a Circle" << std::endl; } }; int main() { Shape* shape1 = new Circle(); shape1->draw(); Circle circle; Shape& shape2 = circle; shape2.draw(); return 0; }
Ques 6 Polymorphism
What will be the output of the following C++ code?
#include<iostream> class A { public: virtual void show() { std::cout << "A" << std::endl; } }; class B : public A { public: void show() override { std::cout << "B" << std::endl; } }; int main() { A* ptrA = new A; A* ptrB = new B; ptrA->show(); ptrB->show(); delete ptrA; delete ptrB; return 0; }