What is the result of code execution?
#include <iostream>
using namespace std;

class A{                                 
public:
   int f(){ 
      return 1; 
   }
    int g(){ 
      return f()+1; 
    }
};

class B: public A{
public:                                 
   int f(){ 
      return 3; 
   }
};

int main() {
   A a;
   B b;
   cout << a.g() << b.g() << endl;      
}
Explanation
Early binding is done at compile time, so the function f() will be called of A class and not the function f() of class B

Follow CodeGalaxy

Mobile Beta

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