Home / C++ Programming / Constructors and Destructors :: General Questions

C++ Programming :: Constructors and Destructors

  1. A constructor that accepts __________ parameters is called the default constructor.

  2. A.
    one
    B.
    two
    C.
    no
    D.
    three

    View Answer

    Workspace

    Discuss Discuss in Forum


  3. What happens when a class with parameterized constructors and having no default constructor is used in a program and we create an object that needs a zero-argument constructor?

  4. A.
    Compile-time error.
    B.
    Preprocessing error.
    C.
    Runtime error.
    D.
    Runtime exception.

    View Answer

    Workspace

    Discuss Discuss in Forum


  5. Can a class have virtual destructor?

  6. A.
    Yes
    B.
    No

    View Answer

    Workspace

    Discuss Discuss in Forum


  7. Destructor has the same name as the constructor and it is preceded by ______ .

  8. A.
    !
    B.
    ?
    C.
    ~
    D.
    $

    View Answer

    Workspace

    Discuss Discuss in Forum


  9. For automatic objects, constructors and destructors are called each time the objects

  10. A.
    enter and leave scope
    B.
    inherit parent class
    C.
    are constructed
    D.
    are destroyed

    View Answer

    Workspace

    Discuss Discuss in Forum


  11. Which of the following statement is correct about the program given below?

     #include 
     class Freshergate
     {   
         int *p;   
         public:   
         FresherGATE(int xx, char ch)    
         {       
             p  = new int();          
            *p = xx + int(ch);          
             coutdelete p;  
       } 
    }; 
    int main() 
    {    
        FresherGATE objGate(10, 'B');      
        return 0;
     }
    

     

     

  12. A.

    The program will print the output 76.

    B.

    The program will print the output 108.

    C.

    The program will print the output garbage value.

    D.

    The program will report compile time error.

    View Answer

    Workspace

    Discuss Discuss in Forum


  13. Which constructor function is designed to copy objects of the same class type?

  14. A.
    Create constructor
    B.
    Object constructor
    C.
    Dynamic constructor
    D.
    Copy constructor

    View Answer

    Workspace

    Discuss Discuss in Forum


  15. Which of the following statement is correct?

  16. 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.

    View Answer

    Workspace

    Discuss Discuss in Forum


  17. Which of the following statement is incorrect?

  18. A.
    Constructor is a member function of the class.
    B.
    The compiler always provides a zero argument constructor.
    C.
    It is necessary that a constructor in a class should always be public.
    D.
    Both B and C.

    View Answer

    Workspace

    Discuss Discuss in Forum


  19. When are the Global objects destroyed?

  20. 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.

    View Answer

    Workspace

    Discuss Discuss in Forum