CPP

CPP

Derived Classes has 9 Questions
Where is the derived class is derived from?

derived
base
both a & b
None of the mentioned
Pick out the correct statement.

A derived class's constructor cannot explicitly invokes its base class's constructor.
A derived class's destructor cannot invoke its base class's destructor.
A derived class's destructor can invoke its base class's destructor.
None of the mentioned
Which of the following can derived class inherit?

members
functions
both a & b
None of the mentioned
What is the output of this program?
  1.     #include 
  2.     using namespace std;
  3.     class A
  4.     {
  5.         public:
  6.         A(int n )
  7.         {
  8.             cout << n;
  9.         }
  10.     };
  11.     class B: public A
  12.     {
  13.         public:
  14.         B(int n, double d)
  15.         : A(n)
  16.         {
  17.             cout << d;
  18.         }    
  19.     };
  20.     class C: public B
  21.     {
  22.         public:
  23.         C(int n, double d, char ch)
  24.         : B(n, d)
  25.         {
  26.             cout <<ch;
  27.         }
  28.     };
  29.     int main()
  30.     {
  31.         C c(5, 4.3, 'R');
  32.         return 0;
  33.     }

54.3R
R4.35
4.3R5
None of the mentioned
What is the output of this program?
  1.     #include 
  2.     using namespace std;
  3.     class Parent
  4.     {
  5.         public:
  6.         Parent (void) 
  7.         {     
  8.             cout << "Parent()\n";
  9.         }
  10.         Parent (int i) 
  11.         { 
  12.             cout << "Parent("<< i << ")\n"; 
  13.         };
  14.         Parent (void) 
  15.         { 
  16.             cout << "~Parent()\n";
  17.         }; 
  18.     };
  19.     class Child1 : public Parent { };
  20.     class Child2 : public Parent
  21.     {
  22.         public:
  23.         Child2 (void) 
  24.         {
  25.             cout << "Child2()\n";
  26.         }
  27.         Child2 (int i) : Parent (i) 
  28.         {
  29.             cout << "Child2(" << i << ")\n"; 
  30.         }
  31.         ~Child2 (void) 
  32.         {
  33.             cout << "~Child2()\n"; 
  34.         }
  35.     };
  36.     int main (void)
  37.     {
  38.         Child1 a;
  39.         Child2 b;
  40.         Child2 c(42);
  41.         return 0;
  42.     }

Parent() Parent() Child2() Parent(42) Child2(42) ~Child2() ~Parent() ~Child2() ~Parent() ~Parent()
error
runtime error
None of the mentioned
What is the output of this program?
  1.     #include
  2.     using namespace std;
  3.     class X 
  4.     {
  5.         int m;
  6.         public:
  7.         X() : m(10)
  8.         {                                                       
  9.         }
  10.         X(int mm): m(mm)
  11.         {
  12.         }
  13.         int getm()
  14.         {
  15.             return m;
  16.         }
  17.     };
  18.     class Y : public X 
  19.     {
  20.         int n;
  21.         public:
  22.         Y(int nn) : n(nn) {}                                                
  23.         int getn() { return n; }
  24.     };
  25.     int main()
  26.     {
  27.         Y yobj( 100 );
  28.         cout << yobj.getm() << " " << yobj.getn() << endl;
  29.     }

10 100
100 10
10 10
100 100
Which operator is used to declare the destructor?

#
~
@
$
Which constructor will initialize the base class data member?

derived class
base class
class
None of the mentioned
What is the output of this program?
  1.     #include 
  2.     using namespace std;
  3.     class Base
  4.     {
  5.         public:
  6.         int m;
  7.         Base(int n=0)
  8.         : m(n)
  9.         {
  10.             cout << "Base" << endl;
  11.         }
  12.     };
  13.     class Derived: public Base
  14.     {
  15.         public:
  16.         double d;
  17.         Derived(double de = 0.0)
  18.         : d(de)
  19.         {
  20.             cout << "Derived" << endl;
  21.         }
  22.     };
  23.     int main()
  24.     {
  25.         cout << "Instantiating Base" << endl;
  26.         Base cBase;
  27.         cout << "Instantiating Derived" << endl;
  28.         Derived cDerived;
  29.         return 0;
  30.     }

Instantiating Base Base Instantiating Derived Base Derived
Instantiating Base Instantiating Derived Base Derived
Instantiating Base Base Instantiating Derived Base
None of the mentioned