12.3.1. Polymorphism: Test Yourself

Study the two classes and their member functions. Based on the objects main instantiates and assigns, determine which functions the program calls (i.e., to which function each call binds). Fill in the blanks (a) to (l) with the appropriate class name: Parent or Child. There is a link to the answers at the bottom of the page.

class Parent
{
    public:
		void funcA() { . . . }
	virtual	void funcB() { . . . }
		void funcC() { . . . }
};


class Child : public Parent
{
    public:
		void funcA() { . . . }
	virtual	void funcB() { . . . }
};


int  main()
{
	Parent*	P1 = new  Parent;
	Parent*	P2 = new  Child;
	Child*	C1 = new  Child;
	Child	temp;
	Parent	P3 = temp;


	P1->funcA();		// (a)_______________
	P1->funcB();		// (b)_______________
	P1->funcC();		// (c)_______________

	P2->funcA();		// (d)_______________
	P2->funcB();		// (e)_______________
	P2->funcC();		// (f)_______________

	C1->funcA();		// (g)_______________
	C1->funcB();		// (h)_______________
	C1->funcC();		// (i)_______________

	P3.funcA();		// (j)_______________
	P3.funcB();		// (k)_______________
	P3.funcC();		// (l)_______________

	return 0;
}

Solution