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

Следи за CodeGalaxy

Мобильное приложение Beta

Get it on Google Play
Обратная Связь
Cosmo
Зарегистрируйся сейчас
или Подпишись на будущие тесты