Introduction to OOP Chapter 16: Overriding : next previous audio real text

Shadowing Methods

Many of those languages that require the virtual keyword in the parent class will use shadowing if it is omitted:
class Parent {
public: 	// note, no virtual keyword here
	void example () { cout << "Parent" << endl; }
};

class Child : public Parent {
public:
	void example () { cout << "Child" << endl; }
};

	Parent * p = new Parent();
	p->example()
Parent
	Child * c = new Child();
	c->example()
Child
	p = c; // be careful here!
	p->example()
Parent
Intro OOP, Chapter 16, Slide 20