logo

CuriousTab

CuriousTab

Constructors and Destructors problems


  • 1. If the programmer does not explicitly provide a destructor, then which of the following creates an empty destructor?

  • Options
  • A. Preprocessor
  • B. Compiler
  • C. Linker
  • D. main() function
  • Discuss
  • 2. When are the Global objects destroyed?

  • Options
  • A. When the control comes out of the block in which they are being used.
  • B. When the program terminates.
  • C. When the control comes out of the function in which they are being used.
  • D. As soon as local objects die.
  • Discuss
  • 3. Which of the following statement is correct?

  • Options
  • A. Constructor has the same name as that of the class.
  • B. Destructor has the same name as that of the class with a tilde symbol at the beginning.
  • C. Both A and B.
  • D. Destructor has the same name as the first member function of the class.
  • Discuss
  • 4. Which of the following implicitly creates a default constructor when the programmer does not explicitly define at least one constructor for a class?

  • Options
  • A. Preprocessor
  • B. Linker
  • C. Loader
  • D. Compiler
  • Discuss
  • 5. Which of the following never requires any arguments?

  • Options
  • A. Member function
  • B. Friend function
  • C. Default constructor
  • D. const function
  • Discuss
  • 6. How many times a constructor is called in the life-time of an object?

  • Options
  • A. Only once
  • B. Twice
  • C. Thrice
  • D. Depends on the way of creation of object
  • Discuss
  • 7. Which of the following statement is correct whenever an object goes out of scope?

  • Options
  • A. The default constructor of the object is called.
  • B. The parameterized destructor is called.
  • C. The default destructor of the object is called.
  • D. None of the above.
  • Discuss
  • 8. Which of the following gets called when an object is being created?

  • Options
  • A. constructor
  • B. virtual function
  • C. destructor
  • D. main
  • Discuss
  • 9. Which constructor function is designed to copy objects of the same class type?

  • Options
  • A. Create constructor
  • B. Object constructor
  • C. Dynamic constructor
  • D. Copy constructor
  • Discuss
  • 10. 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 << this->x   << " " 
                 << this->y   << " "  
                 << objBase.x << " "
                 << objBase.y << " ";
        } 
        ~CuriousTabDerived()
        { }
    };
    int main()
    {
        CuriousTabDerived objDev(11, 22); 
        return 0;
    }

  • Options
  • A. 11 22 0 0
  • B. 11 0 0 22
  • C. 11 0 22 0
  • D. 11 22 11 22
  • E. The program will report compile time error.
  • Discuss

First 2 3 4 5 6