CPP

CPP

Design of Class Hierarchies has 9 Questions

Which interface determines how your class will be used by other program?

public
private
protected
None of the mentioned
Pick out the correct statement about override.

Overriding refers to a derived class function that has the same name and signature as a base class virtual function.
Overriding has different names.
both a & b
None of the mentioned
How many ways of reusing are there in class hierarchy?

1
2
3
4
How many types of class are there in c++?

1
2
3
4
Pick out the correct statement about multiple inheritance.

Deriving a class from one direct base class
Deriving a class from more than one direct base class
Deriving a class from more than one direct derived class
None of the mentioned
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.     }

10
20
1020
None of the mentioned
What does inheriatance allows you to do?

create a class
create a hierarchy of classes
access methods
None of the mentioned
What is the syntax of inheritance of class?

class name
class name : access specifer
class name : access specifer class name
None of the mentioned
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.     }

123
12
213
321