LogiQuest
Back to Polymorphism and Virtual Functions
11

What will be the output of the program?

#include <iostream>
using namespace std;
class A {
public:
    virtual int g() { return 1; }
    int call() { return g(); }
    virtual ~A() {}
};
class B : public A { public: int g() override { return 2; } };
int main() {
    B b;
    cout << b.call() << endl;
    return 0;
}
Medium

Discussion (0)

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

Log in to join the discussion.