0

I am new to object oriented programming , so I have a vague understanding of the overriding concept. However , the following example totally confuses me:

class Base {
  public:
    void Hello() {
      cout << "hello world from the BASE class" << endl;
    }

  void printHello() {
    for (int i = 0; i <= 5; i++) {
      Hello();
    }
  }

};

class Derived: public Base {
  public: void Hello() {
    cout << "hello world from the DERIVED class";
  }
};

int main() {
  Derived obj;
  obj.printHello();
  return 0;
}

expected result: 5* "hello world from the DERIVED class"

result: 5* "hello world from the BASE class"

Shouln't the Hello() function in the BASE class be replaced by the one in the DERIVED class? If not , how can I obtain this?

Thanks in advance!

JayDew
  • 41
  • 1
  • 6

0 Answers0