







Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!








(^) Subtype Polymorphism (^) Dynamic Binding (^) Virtual Methods (^) Dynamic Dispatch (^) Abstract Class
Assume dynamic binding is being used: X x; Y y; Z z; X *px; : cin >> val; if (val == 1) px = &x; else px = &y; px->print(); // which print() is used?
class person { … virtual void print () { // print person details } };
pb = &b; cout << "pb now points to b\n"; cout << "Calling pb->print()\n"; pb->print(); // uses B::print() pb = &d; cout << "pb now points to d\n"; cout << "Calling pb->print()\n"; pb->print(); // uses D::print() return 0; }