Design of Class Hierarchies

1

What is the syntax of inheritance of class?

A. class name
B. class name : access specifer
C. class name : access specifer class name
D. None of the mentioned

2

What does inheriatance allows you to do?

A. create a class
B. create a hierarchy of classes
C. access methods
D. None of the mentioned

3

What is the output of this program?

1.
    #include 
2.
    using namespace std;
3.
    class BaseClass 
4.
    {
5.
        public:
6.
        virtual void myFunction()
7.
        {
8.
            cout << "1";
9.
        }
10.
    };
11.
    class DerivedClass1 : public BaseClass 
12.
    {
13.
        public:
14.
        void myFunction()
15.
        {
16.
            cout << "2";
17.
        }
18.
    };
19
   class DerivedClass2 : public DerivedClass1
20.
    {
21.
        public:
22.
        void myFunction()
23.
        {
24.
            cout << "3";
25.
        }
26.
    };
27.
    int main()
28.
    {
29.
        BaseClass *p;
30.
        BaseClass ob;
31.
        DerivedClass1 derivedObject1;
32.
        DerivedClass2 derivedObject2;
33.
        p = &ob;
34.
        p -> myFunction();
35.
        p = &derivedObject1;
36.
        p -> myFunction();
37.
        p = &derivedObject2;
38.
        p -> myFunction();
39.
        return 0;
40.
    }
A. 123
B. 12
C. 213
D. 321

4

What is the output of this program?

1.
    #include 
2.
    using namespace std;
3.
    class BaseClass 
4.
    {
5.
        int x;
6.
        public:
7.
        void setx(int n) 
8.
        {
9.
            x = n;
10.
        }
11.
        void showx() 
12.
        {
13.
            cout << x ;
14.
        }
15.
    };
16.
    class DerivedClass : private BaseClass
17.
    {
18.
        int y;
19.
        public:
20.
        void setxy(int n, int m)
21.
        {
22.
            setx(n);  
23.
            y = m;
24.
        }
25.
        void showxy() 
26.
        {
27.
            showx();   
28.
            cout << y << '\n';
29.
        }
30.
    };
31.
    int main()
32.
    {
33.
        DerivedClass ob;
34.
        ob.setxy(10, 20);
35.
        ob.showxy();
36.
        return 0;
37.
    }
A. 10
B. 20
C. 1020
D. None of the mentioned

5

Pick out the correct statement about multiple inheritance.

A. Deriving a class from one direct base class
B. Deriving a class from more than one direct base class
C. Deriving a class from more than one direct derived class
D. None of the mentioned