What will be printed out as a result of the following code execution?
#include<iostream>

class Base
{
   public:
      virtual void f() { std::cout << "Base"; }
};

class Child : public Base
{
   public:
      int f() { std::cout << "Child"; }
};

int main()
{
   Child c;
   c.f();
}
Explanation
Since the f() function is declared as virtual in the Base class, the compiler will not allow to change its return type in the derived Child class.

Follow CodeGalaxy

Mobile Beta

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