LogiQuest
Back to Polymorphism and Virtual Functions
4

What will be the output of the program?

#include <iostream>
using namespace std;
class A { public: virtual int v() { return 1; } virtual ~A() {} };
class B : public A { public: int v() override { return 2; } };
int main() {
    A a = B();
    cout << a.v() << endl;
    return 0;
}
Hard

Discussion (0)

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

Log in to join the discussion.