Abstract Classes

1

Where does the abstract class is used?

A. base class only
B. derived class
C. both a & b
D. None of the mentioned

2

Pick out the correct option.

A. We cannot make an instance of an abstract base class
B. We can make an instance of an abstract base class
C. Both a & b
D. None of the mentioned

3

What is meant by pure virtual function?

A. Function which does not have definition of its own.
B. Function which does have definition of its own.
C. Function which does not have any return type.
D. None of the mentioned

4

What is the output of this program?

1.
    #include 
2.
    using namespace std;
3.
    class Base
4.
    {
5.
        public:
6.
        virtual void print() const = 0;
7.
    };
8.
    class DerivedOne : virtual public Base
9.
    {
10.
        public:
11.
        void print() const
12.
        {
13.
            cout << "1";
14.
        }
15.
    };
16.
    class DerivedTwo : virtual public Base
17.
    {
18.
        public:
19.
        void print() const
20.
        {
21.
            cout << "2";
22.
        }
23.
    };
24.    
    class Multiple : public DerivedOne, DerivedTwo
25.
    {
26.
        public:
27.
        void print() const
29.
        {
29.
            DerivedTwo::print();
30.
        }
31.
    };
32.
    int main()
33.
    {
34.
        Multiple both;
35.
        DerivedOne one;
36.
        DerivedTwo two;
37.
        Base *array[ 3 ];
38.
        array[ 0 ] = &both;
39.
        array[ 1 ] = &one;
40.
        array[ 2 ] = &two;
41.
        for ( int i = 0; i < 3; i++ )
42.
        array[ i ] -> print();
43.
        return 0;
44.
    }
A. 121
B. 212
C. 12
D. None of the mentioned

5

What is the output of this program?

1.
    #include 
2.
    using namespace std;
3.
    class sample
4.
    {
5.
        public:
6.
        virtual void example() = 0; 
7.
    };
8.
    class Ex1:public sample
9.
    {
10.
        public:
11.
        void example()
12.
        {
13.
            cout << "ubuntu";
14.
        }
15.
    };
16.
    class Ex2:public sample
17.
    {
18.
        public:
19.
        void example()
20.
        {
21.
            cout << " is awesome";
22.
        }
23.
    };
24.
    int main()
25.
    {
26.
        sample* arra[2];
27.
        Ex1 e1;
28.
        Ex2 e2;
29.
        arra[0]=&e1;
30.
        arra[1]=&e2;
31.
        arra[0]->example();
32.
        arra[1]->example();
33.
    }
A. ubuntu
B. is awesome
C. ubuntu is awesome
D. None of the mentioned