Question
#include <iostream>
using namespace std;
struct A
{
virtual void f()
{
cout << "Class A" << endl;
}
};
struct B : A
{
virtual void f()
{
cout << "Class B" << endl;
}
};
struct C : A
{
virtual void f()
{
cout << "Class C" << endl;
}
};
void f(A* arg)
{
B* bp = dynamic_cast<B*>(arg);
C* cp = dynamic_cast<C*>(arg);
if (bp)
bp -> f();
else if (cp)
cp -> f();
else
arg -> f();
};
int main()
{
A aobj;
C cobj;
A* ap = &cobj;
A* ap2 = &aobj;
f(ap);
f(ap2);
}
a.
Class C
b.
Class A
c.
Both Class C & A
d.
None of the mentioned
Posted under Object Oriented Programming Using C++
Engage with the Community - Add Your Comment
Confused About the Answer? Ask for Details Here.
Know the Explanation? Add it Here.
Q. What is the output of this program?
Similar Questions
Discover Related MCQs
Q. What is meant by type_info?
View solution
Q. At which time does the static_cast can be applied?
View solution
Q. Which is referred by pointers to member?
View solution
Q. What should be used to point to a static class member?
View solution
Q. Which operator is used in pointer to member function?
View solution
Q. Which is the best design choice for using pointer to member function?
View solution
Q. What is the operation for .*?
View solution
Q. Which is used to allocate and deallocate storage for objects during the execution?
View solution
Q. Which operators are used in the free store?
View solution
Q. What type of class member is operator new?
View solution
Q. What must be an operand of operator delete?
View solution
Q. How can object be allocated outside the object lifetime?
View solution
Q. Pick out the wrong header file about strings.
View solution
Q. Which is best for coding the standard libary for c++?
View solution
Q. What is meant by vector in the container library contains?
View solution
Q. Pick out the wrong header file.
View solution
Q. What is meant by standard c++ library?
View solution
Q. Pick out parameter for rehash method in unordered_set in c++?
View solution
Q. What is the use of <exception> header
View solution
Q. How many sets of requirements are need in designing a container?
View solution
Suggested Topics
Are you eager to expand your knowledge beyond Object Oriented Programming Using C++? We've curated a selection of related categories that you might find intriguing.
Click on the categories below to discover a wealth of MCQs and enrich your understanding of Computer Science. Happy exploring!