Consider the following code fragment: class Object { public: virtual void printMe() = 0; }; class Place

Question:

Consider the following code fragment:

class Object
{ public: virtual void printMe() = 0; };
class Place : public Object
{ public: virtual void printMe() { cout << "Buy it.\n"; } };
class Region : public Place
{ public: virtual void printMe() { cout << "Box it.\n"; } };
class State : public Region
{ public: virtual void printMe() { cout << "Ship it.\n"; } };
class Maryland : public State
{ public: virtual void printMe() { cout << "Read it.\n"; } };

int main() { 

Region* mid = new State;
State* md = new Maryland;
Object* obj = new Place;
Place* usa = new Region;
md−>printMe();
mid−>printMe();
(dynamic cast(obj))−>printMe();
obj = md;
(dynamic cast(obj))−>printMe();
obj = usa;
(dynamic cast(obj))−>printMe();
usa = md;
(dynamic cast(usa))−>printMe();
return EXIT SUCCESS;
}

What is the output from calling the main function of the Maryland class?

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question

Data Structures And Algorithms In C++

ISBN: 9780470383278

2nd Edition

Authors: Michael T. Goodrich, Roberto Tamassia, David M. Mount

Question Posted: