Polymorphism Exercises |
< Previous Next > |
#include <iostream> using namespace std; class Base { public: Base() {} virtual void A() { cout << "Base A\n"; } void B() { cout << "Base B\n"; } }; class One : public Base { public: One() {} void A() { cout << "One A\n"; } void B() { cout << "One B\n"; } }; class Two : public Base { public: Two() {} void A() { cout << "Two A\n"; } void B() { cout << "Two B\n"; } }; int main() { Base* base0 = new Base; Base* base1 = new One; Base* base2 = new Two; base0->A(); base0->B(); cout << endl; base1->A(); base1->B(); cout << endl; base2->A(); base2->B(); cout << endl; return 0; }
Last Modified: