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

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

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

int main() {
   A a;
   B b;
   cout << a.g() << b.g() << endl;      
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
Keep exploring
C++ quizzes
Sign Up Now
or Subscribe for future quizzes