CPP

CPP

Abstract Classes has 10 Questions
Which class is used to design the base class?

abstract class
derived class
base class
None of the mentioned
Which is used to create a pure virtual function ?

$
=0
&
!
Which is also called as abstract class?

virtual function
pure virtual function
derived class
None of the mentioned
What is the output of this program?
  1.     #include 
  2.     using namespace std;
  3.     class p 
  4.     {
  5.         protected:
  6.         int width, height;
  7.         public:
  8.         void set_values (int a, int b)
  9.         {
  10.             width = a; height = b; 
  11.         }
  12.         virtual int area (void) = 0;
  13.     };
  14.     class r: public p
  15.     {
  16.         public:
  17.         int area (void)
  18.         { 
  19.             return (width * height);
  20.         }
  21.     };
  22.     class t: public p 
  23.     {
  24.         public:
  25.         int area (void)
  26.         {
  27.             return (width * height / 2); 
  28.         }
  29.     };
  30.     int main () 
  31.     {
  32.         r rect;
  33.         t trgl;
  34.         p * ppoly1 = ▭
  35.         p * ppoly2 = &trgl;
  36.         ppoly1->set_values (4, 5);
  37.         ppoly2->set_values (4, 5);
  38.         cout << ppoly1 -> area() ;
  39.         cout << ppoly2 -> area();
  40.         return 0;
  41.     }

1020
20
10
2010
What is the output of this program?
  1.     #include 
  2.     using namespace std;
  3.     class MyInterface 
  4.     {
  5.         public:
  6.         virtual void Display() = 0;
  7.     };
  8.     class Class1 : public MyInterface 
  9.     {
  10.         public:
  11.         void Display() 
  12.         {
  13.             int  a = 5;
  14.             cout << a;
  15.         }
  16.     };
  17.     class Class2 : public MyInterface 
  18.     {
  19.         public:
  20.         void Display()
  21.         {
  22.             cout <<" 5" << endl;
  23.         }
  24.     };
  25.     int main()
  26.     {
  27.         Class1 obj1;
  28.         obj1.Display();
  29.         Class2 obj2;
  30.         obj2.Display();
  31.         return 0;
  32.     }

5
10
5 5
None of the mentioned
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.     }

ubuntu
is awesome
ubuntu is awesome
None of the mentioned
What is meant by pure virtual function?

Function which does not have definition of its own.
Function which does have definition of its own.
Function which does not have any return type.
None of the mentioned
Pick out the correct option.

We cannot make an instance of an abstract base class
We can make an instance of an abstract base class
Both a & b
None of the mentioned
Where does the abstract class is used?

base class only
derived class
both a & b
None of the mentioned
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
  28.         {
  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.     }

121
212
12
None of the mentioned