What will be printed out as a result of the following code execution?
#include "stdio.h"

class Parent {
  public:
    void GetValue() { Count(); }
  private:
    virtual void Count() { printf("%d", 1); }
};

class Child : public Parent { 
  private:
    void Count() { printf("%d", 2); }
};

int main() {
  Parent * obj = new Child;
  obj->GetValue();
  return 0;
}
Explanation
There is no compilation error because the GetValue() method has access to the Count() method of the base class. But instead of the Count() from base class, the method of descendant is called polymorphically.

Следи за CodeGalaxy

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

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