Welcome to the Class Hierarchies,Library and Containers MCQs Page
Dive deep into the fascinating world of Class Hierarchies,Library and Containers with our comprehensive set of Multiple-Choice Questions (MCQs). This page is dedicated to exploring the fundamental concepts and intricacies of Class Hierarchies,Library and Containers, a crucial aspect of Object Oriented Programming Using C++. In this section, you will encounter a diverse range of MCQs that cover various aspects of Class Hierarchies,Library and Containers, from the basic principles to advanced topics. Each question is thoughtfully crafted to challenge your knowledge and deepen your understanding of this critical subcategory within Object Oriented Programming Using C++.
Check out the MCQs below to embark on an enriching journey through Class Hierarchies,Library and Containers. Test your knowledge, expand your horizons, and solidify your grasp on this vital area of Object Oriented Programming Using C++.
Note: Each MCQ comes with multiple answer choices. Select the most appropriate option and test your understanding of Class Hierarchies,Library and Containers. You can click on an option to test your knowledge before viewing the solution for a MCQ. Happy learning!
Class Hierarchies,Library and Containers MCQs | Page 4 of 15
Explore more Topics under Object Oriented Programming Using C++
#include <iostream>
#include <exception>
using namespace std;
class base { virtual void dummy() {} };
class derived: public base { int a; };
int main ()
{
try
{
base * pba = new derived;
base * pbb = new base;
derived * pd;
pd = dynamic_cast<derived*>(pba);
if (pd == 0)
cout << "Null pointer on first type-cast" << endl;
pd = dynamic_cast<derived*>(pbb);
if (pd == 0)
cout << "Null pointer on second type-cast" << endl;
}
catch (exception& e)
{
cout << "Exception: " << e.what();
}
return 0;
}
#include <iostream>
#include <typeinfo>
using namespace std;
int main ()
{
int * a;
int b;
a = 0; b = 0;
if (typeid(a) != typeid(b))
{
cout << typeid(a).name();
cout << typeid(b).name();
}
return 0;
}
#include <iostream>
#include <typeinfo>
#include <exception>
using namespace std;
class base
{
virtual void f(){}
};
class derived : public base {};
int main ()
{
try
{
base* a = new base;
base* b = new derived;
cout << typeid(*a).name() << '\t';
cout << typeid(*b).name();
}
catch (exception& e)
{
cout << "Exception: " << e.what() << endl;
}
return 0;
}
#include <typeinfo>
#include <iostream>
using namespace std;
class A
{
public:
virtual ~A();
};
int main()
{
A* a = NULL;
try
{
cout << typeid(*a).name() << endl;
}
catch (bad_typeid)
{
cout << "Object is NULL" << endl;
}
}
#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);
}
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!