logo

CuriousTab

CuriousTab

Discussion


Home C++ Programming Constructors and Destructors See What Others Are Saying!
  • Question
  • Which of the following statements are correct?


  • Options
  • A. Constructor is always called explicitly.
  • B. Constructor is called either implicitly or explicitly, whereas destructor is always called implicitly.
  • C. Destructor is always called explicitly.
  • D. Constructor and destructor functions are not called at all as they are always inline.

  • Correct Answer
  • Constructor is called either implicitly or explicitly, whereas destructor is always called implicitly. 


  • More questions

    • 1. Which of the following statement is incorrect?

    • Options
    • A. The default value for an argument can be a global constant.
    • B. The default arguments are given in the function prototype.
    • C. Compiler uses the prototype information to build a call, not the function definition.
    • D. The default arguments are given in the function prototype and should be repeated in the function definition.
    • Discuss
    • 2. Which of the following statement is correct?

    • Options
    • A. A constructor of a derived class can access any public and protected member of the base class.
    • B. Constructor cannot be inherited but the derived class can call them.
    • C. A constructor of a derived class cannot access any public and protected member of the base class.
    • D. Both A and B.
    • Discuss
    • 3. Which of the following statements about virtual base classes is correct?

    • Options
    • A. It is used to provide multiple inheritance.
    • B. It is used to avoid multiple copies of base class in derived class.
    • C. It is used to allow multiple copies of base class in a derived class.
    • D. It allows private members of the base class to be inherited in the derived class.
    • Discuss
    • 4. Which of the following statement is correct about the program given below?
      #include<iostream.h> 
      int main()
      {
          int x = 10, y = 20;
          int *ptr = &x;
          int &ref = y;
      
          *ptr++;
           ref++;    
      
          cout<< x << " " << y;
          return 0; 
      }

    • Options
    • A. The program will print the output 10 20.
    • B. The program will print the output 10 21.
    • C. The program will print the output 11 20.
    • D. The program will print the output 11 21.
    • E. It will result in a compile time error.
    • Discuss
    • 5. What will be the out of the following program?
      #include<iostream.h> 
      class CuriousTabBase
      {
          public:
          int x, y; 
          public:
          CuriousTabBase(int xx = 0, int yy = 0)
          {
              x = xx;
              y = yy; 
          } 
       };
      class CuriousTabDerived : public CuriousTabBase
      {
          private:
              CuriousTabBase objBase; 
          public:
          CuriousTabDerived(int xx, int yy) : CuriousTabBase(xx), objBase(yy)
          {
              cout << x          << " " 
                   << this->x    << " "  
                   << CuriousTabBase::x << " "     
                   << this->objBase.x ;
          } 
          ~CuriousTabDerived()
          { }
      };
      int main()
      {
          CuriousTabDerived objDev(11, 22); 
          return 0;
      }

    • Options
    • A. 11 22 0 0
    • B. 11 11 0 22
    • C. 11 11 11 0
    • D. 11 11 11 22
    • E. The program will report compile time error.
    • Discuss
    • 6. Which of the following statement is correct about the program given below?
      #include<iostream.h>
      class CuriousTab
      {
          int x, y, z; 
          public:
          CuriousTab(int x = 100, int y = 30, int z = 0)
          {
              this->x = x; 
              this->y = y;
              this->z = z; 
              Display();
          }
          void Display()
          {
              cout<< x << " " << y << " " << z;
          }
      };
      int main()
      {
          int a = 0, b = 1, c = 2; 
          int &x = ++a; 
          int &y = --b; 
          int z = c + b - -c; 
          CuriousTab objCuriousTab(x, y, z); 
          return 0; 
      }

    • Options
    • A. The program will print the output 1 0 3.
    • B. The program will print the output 1 0 4.
    • C. The program will print the output 1 1 3.
    • D. The program will print the output 1 1 4.
    • E. The program will report compile time error.
    • Discuss
    • 7. Which of the following statement is correct about the program given below?
      #include<iostream.h>
      #include<string.h>
      #include<malloc.h>
      class CuriousTabString
      {
          char txtName[20]; 
          public:
          CuriousTabString(char *txtTemp = NULL)
          {
              if(txtTemp != NULL)
              strcpy(txtName, txtTemp);
          }
          void Display(void)
          {
              cout<<txtName;
          }
      };
      int main()
      {
          char *txtName = (char*)malloc(10);
          strcpy(txtName, "CuriousTab");
          *txtName = 48;
          CuriousTabString objTemp(txtName);
          cout<< sizeof(txtName);
          return 0; 
      }

    • Options
    • A. Above program will display CuriousTab 8.
    • B. Above program will display CuriousTab 9.
    • C. Above program will display size of integer.
    • D. Above program will display CuriousTab and size of integer.
    • E. Above program will display 1.
    • Discuss
    • 8. What is correct about the following program?
      #include<iostream.h> 
      class Addition
      {
          int x; 
          public: 
          Addition()
          {
              x = 0;
          }       
          Addition(int xx)
          {
              x = xx;
          }
          Addition operator + (int xx = 0)
          {
              Addition objTemp; 
              objTemp.x = x + xx; 
              return(objTemp);
          }
          void Display(void)
          {
              cout<< x << endl;
          }
      };
      int main()
      {
          Addition objA(15), objB;
          objB = objA + 5;
          objB.Display();
          return 0; 
      }

    • Options
    • A. The program will print the output 20.
    • B. The program will report run time error.
    • C. The program will print the garbage value.
    • D. Compilation fails due to 'operator +' cannot have default arguments.
    • Discuss
    • 9. Which of the following statement is correct about the program given below?
      #include<iostream.h> 
      class CuriousTabBase
      {
          int x, y; 
          public:
          CuriousTabBase(int xx = 10, int yy = 10)
          {
              x = xx;
              y = yy;
          }
          void Show()
          {
              cout<< x * y << endl;
          }
      };
      class CuriousTabDerived
      {
          private:
              CuriousTabBase objBase; 
          public:
          CuriousTabDerived(int xx, int yy) : objBase(xx, yy)
          {
              objBase.Show();
          }
      };
      int main()
      {
          CuriousTabDerived objDev(10, 20);
          return 0; 
      }

    • Options
    • A. The program will print the output 100.
    • B. The program will print the output 200.
    • C. The program will print the output Garbage-value.
    • D. The program will report compile time error.
    • Discuss
    • 10. What will be the output of the following program?
      #include<iostream.h> 
      class Point
      {
          int x, y; 
          public:
          Point(int xx = 10, int yy = 20)
          {
              x = xx;
              y = yy; 
          }
          Point operator + (Point objPoint)
          {
              Point objTmp;
              objTmp.x = objPoint.x + this->x; 
              objTmp.y = objPoint.y + this->y;
              return objTmp;
          }
          void Display(void)
          {
              cout<< x << " " << y;
          }
      };
      int main()
      {
          Point objP1;
          Point objP2(1, 2);
          Point objP3 = objP1 + objP2;
          objP3.Display(); 
          return 0; 
      }

    • Options
    • A. 1 2
    • B. 10 20
    • C. 11 22
    • D. Garbage Garbage
    • E. The program will report compile time error.
    • Discuss


    Comments

    There are no comments.

Enter a new Comment