Question: Given the class inheritance hierarchy where Corporation is a base class and PublicCorporation and PrivateCorporation are derived classes. Suppose ForProfitPrivate and NonProfitPivate are derived from

Given the class inheritance hierarchy where Corporation is a base class and

PublicCorporation and PrivateCorporation are derived classes. Suppose ForProfitPrivate and NonProfitPivate are derived from PrivateCorporation. Suppose that each class is written in C++ and defines a head() member function, and suppose that ph[] is an array of pointers to the Corporation type, and suppose that ph[] is assigned the addresses of one of each of the derived objects as follows:

PublicCorporation pc;

PrivateCorporation pv;

ForProfitPrivate fppv;

NonProfitPrivate nppv; Corporation *ph[4]; ph[0] = &pc; ph[1] = &pv; ph[2] = &fppv;

ph[3] = &nppv;

Explain how ph[i]->head() is interpreted for a given index i if the base class defines head() as follows: (a) Regular non-virtual method (no polymorphism) (b) Virtual method (polymorphism).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!