Run Time Type Information

1

At which time does the static_cast can be applied?

A. Compile-time construct
B. Runtime construct
C. Both a & b
D. None of the mentioned

2

What is meant by type_info?

A. Used to hold the type information returned by the typeid operator
B. Used to hold the type information returned by the dynamic_cast
C. Used to hold the type information returned by the static cast
D. None of the mentioned

3

What is the output of this program?

 
1.
    #include 
2.
    using namespace std;
3.
    struct A 
4.
    {
5.
        virtual void f()  
6.
        { 
7.
            cout << "Class A" << endl; 
8.
        }
9.
    };
10.
    struct B : A 
11.
    {
12.
        virtual void f() 
13.
        { 
14.
            cout << "Class B" << endl;
15.
        }
16.
    };
17.
    struct C : A 
18.
    {
19.    
        virtual void f() 
20.
        {
21.
            cout << "Class C" << endl; 
22.
        }
23.
    };
24.
    void f(A* arg) 
25.
    {
26.
        B* bp = dynamic_cast(arg);
27.
        C* cp = dynamic_cast(arg);
28.
        if (bp)
29.
            bp -> f();
30.
        else if (cp)
31.
            cp -> f();
32.
        else
33.
            arg -> f();  
34.
    };
35.
    int main() 
36.
    {
37.
        A aobj;
38.
        C cobj;
39.
        A* ap = &cobj;
40.
        A* ap2 = &aobj;
41.
        f(ap);
42.
        f(ap2);
43.
    }
A. Class C
B. Class A
C. Both a & b
D. None of the mentioned

4

What is the output of this program?

1.
    #include 
2.
    #include 
3.
    using namespace std;
4.
    class A
5.
    {
6.
        public:
7.
        virtual ~A();
8.
    };
9.
    int main() 
10.
    {
11.
        A* a = NULL;
12.
        try 
13.
        {
14.
            cout << typeid(*a).name() << endl; 
15.
        }
16.
        catch (bad_typeid)
17.
        {
18.
            cout << "Object is NULL" << endl;
19.
        }
20.
    }
A. int
B. float
C. double
D. object is NULL

5

What is the output of this program?

1.
    #include 
2.
    #include 
3.
    #include 
4.
    using namespace std;
5.
    class base 
6.
    { 
7.
        virtual void f(){} 
8.
    };
9.
    class derived : public base {};
10.
    int main () 
11.
    {
12.
        try 
13.
        {
14.
            base* a = new base;
15.
            base* b = new derived;
16.
            cout << typeid(*a).name() << 't';
17.
            cout << typeid(*b).name();
18.
        } 
19.
        catch (exception& e) 
20.
        { 
21.
            cout << "Exception: " << e.what() << endl; 
22.
        }
23.
        return 0;
24.
    }
A. base*
B. derived*
C. 4base and 7derived
D. None of the mentioned