Question: Question 2 : Recall that in C + + virtual functions use dynamic dispatch and non - virtual functions use static dispatch. Consider the C

Question 2: Recall that in C++ virtual functions use dynamic dispatch and non-virtual functions use static dispatch. Consider the C++ program: #include using namespace std; class A { public: virtual void foo (){ cout <<"A"<< endl; }}; class B : public A { public: virtual void foo (){ cout <<"B"<< endl; }}; class C : public B { public: virtual void foo (){ cout <<"C"<< endl; }}; int main (){ B* x = new C (); x->foo (); }
What will happen when the program is compiled and executed? A : Prints C. B : Prints BA. C : Prints CBA. D : Prints A. E : Prints B.

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 Programming Questions!