LogiQuest
Back to Polymorphism and Virtual Functions
1

What will be the output of the program?

#include <iostream>
using namespace std;
class Shape { public: virtual const char* name() { return "shape"; } virtual ~Shape() {} };
class Circle : public Shape { public: const char* name() override { return "circle"; } };
int main() {
    Shape *s = new Circle();
    cout << s->name() << endl;
    delete s;
    return 0;
}
Easy

Discussion (0)

  • No discussion yet. Ask a doubt or share a shortcut.

Log in to join the discussion.