Sail E0 Webinar
Question


What is the output of this program?


1.
#include
2.
#include
3.
using namespace std;
4.
class shape
5.
{
6.
public:
7.
virtual void myvirtualfunc() const {}
8.
};
9.
class mytriangle: public shape
10.
{
11.
public:
12.
virtual void myvirtualfunc() const
13.
{
14.
};
15.
};
16.
int main()
17.
{
18.
shape shape_instance;
19.
shape &ref_shape = shape_instance;
20.
try
21.
{
22.
mytriangle &ref_mytriangle = dynamic_cast(ref_shape);
23.
}
24.
catch (bad_cast)
25.
{
26.
cout
Options:
A .  Caught standard exception
B .  No exception arises
C .  Caught: bad_cast exception
D .  None of the mentioned
Answer: Option C

As we are not able to allocate the values by using dynamic cast,
So it is arising an exception.
Output:
$ g++ std3.cpp
$ a.out
Caught: bad_cast exception



Was this answer helpful ?
Next Question

Submit Solution

Your email address will not be published. Required fields are marked *

Latest Videos

Latest Test Papers