Having the polymorphic methods in consturctors, what will be printed as a result of the program?
#include <iostream>
class A
{
private:
    virtual void VirtualMethod()
    {
        std::cout << "A::VirtualMethod()";
    }

public:
    A()
    {
        VirtualMethod();
    }
};

class B : public A
{
private:
    virtual void VirtualMethod()
    {
        std::cout << "B::VirtualMethod()";
    }
};

void main()
{
    A* a = new B();
    delete a;
}

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
C++ quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes