Home » C++ Programming » Exception Handling » Question
  1. What is the output of this program?
    #include <typeinfo>
    #include <iostream>
    using namespace std;
    class AngleShape
    {
    public:
    virtual void myvirtualfunc() const {}
    };
    class Triangle: public AngleShape
    {
    public:
    virtual void myvirtualfunc() const
    {
    };
    };
    int main()
    {
    AngleShape Angleshape_instance;
    AngleShape &ref_Angleshape = Angleshape_instance;
    try
    {
    Triangle &ref_Triangle = dynamic_cast <Triangle& > (ref_Angleshape);
    }
    catch (bad_cast)
    {
    cout << "Can't do the Dynamic_cast" << endl;
    cout << "Caught: bad_cast exception. AngleShape is not Triangle.\n";
    }
    return 0;
    }
    1. Can’t able to create the dynamic instance for the triangle, So it is arising an exception
    2. Compilation Error
    3. Runtime Error
    4. Can't do the Dynamic_cast
    5. None of these
Correct Option: A

As we can’t able to create the dynamic instance for the triangle, So it is arising an exception.



Your comments will be displayed only after manual approval.