Constructors interview questions

24 questions. Tap “Show answer” to check yourself.

Advertisement
  1. A destructor name must be

    1. same as class name prefixed by tilde (~) character
    2. same as class name
    3. same as any other member function name
    4. none of the given
    Show answer

    A. same as class name prefixed by tilde (~) character

  2. Which of the following prototype can be a copy constructor of class myclass?

    1. myclass (myclass & ×)
    2. myclass copy (myclass a)
    3. int copy (myclass mc)
    4. myclass (int myclass)
    Show answer

    A. myclass (myclass & ×)

  3. A copy constructor is invoked when

    1. an object is passed by reference to constructor
    2. a member function returns an object
    3. an object is passed as a parameter to any of the member function
    4. all of the above
    Show answer

    D. all of the above

  4. Which of the following is not true?

    1. Destructors cannot be overloaded
    2. Constructor can have parameters
    3. Constructor is executed automatically
    4. Constructor cannot be Overloaded
    Show answer

    D. Constructor cannot be Overloaded

  5. Which of the following is false?

    1. Constructor and member function have same name
    2. Class and destructor have same name
    3. Class and constructor have same name
    4. Constructor and destructor have same name
    Show answer

    A. Constructor and member function have same name

  6. Which of the following is automatically executed when the control reaches the end of class scope?

    1. Inline function
    2. Member function
    3. Destructor
    4. Constructor
    Show answer

    C. Destructor

  7. Which of the following is a function that removes the allocated memory of an object?

    1. Copy constructor
    2. Member function
    3. Destructor
    4. Constructor
    Show answer

    C. Destructor

  8. Which of the following is true?

    1. The constructor function can be overloaded
    2. The constructor is executed automatically
    3. A constructor can have parameter list
    4. All the given are true
    Show answer

    D. All the given are true

  9. Which one of the following initializes a class object and allocates memory space?

    1. Member function
    2. Constructor
    3. Destructor
    4. None of the given
    Show answer

    B. Constructor

  10. When a class object goes out of scope, the function that gets executed is ____

    1. Constructor
    2. Destructor
    3. Friend
    4. Inline
    Show answer

    B. Destructor

  11. Which is executed automatically when the control reaches the end of the class scope?

    1. Constructor
    2. Destructor
    3. Overloading
    4. Copy constructor
    Show answer

    B. Destructor

  12. The special character related to destructor is ___

    1. +
    2. !
    3. ?
    4. ~
    Show answer

    D. ~

  13. Advertisement
  14. The constructor without any parameter is called as ___

    1. Initial constructor
    2. Parameterized constructor
    3. Default constructor
    4. Instance parameter
    Show answer

    B. Parameterized constructor

  15. The constructor defined by the computers in the absence of user defined constructor is ____

    1. Copy
    2. Abstract
    3. Default
    4. Destructor
    Show answer

    C. Default

  16. The constructors defined by the computers in the absence of user defined constructor is called as ____

    1. Non-parameterized
    2. Default
    3. Compiler generated
    4. All of these
    Show answer

    C. Compiler generated

  17. How many destructors a class can have?

    1. 1
    2. 2
    3. 3
    4. 4
    Show answer

    A. 1

  18. Constructor should be declared under the scope ___

    1. Public
    2. Private
    3. Protected
    4. Pointer
    Show answer

    A. Public

  19. Which of the following cannot have arguments?

    1. Operator overloading
    2. Function overloading
    3. Constructor
    4. Destructor
    Show answer

    D. Destructor

  20. Which of the following do not return any value ____

    1. Constructor and destructor
    2. Friend functions
    3. Inline functions
    4. Member functions
    Show answer

    A. Constructor and destructor

  21. When an instance of a class comes into scope, the function that executed is ____

    1. Destructor
    2. Constructor
    3. Inline
    4. Friend
    Show answer

    B. Constructor

  22. The destructor is prefixed by the character ___

    1. ~
    2. %
    3. #
    4. &
    Show answer

    A. ~

  23. Which one of the following is automatically executed when an object is created?

    1. Constructor
    2. Destructor
    3. Inline function
    4. Member function
    Show answer

    A. Constructor

  24. The name of constructor must be ___

    1. Same as object name
    2. Same as one of the member function
    3. Same as class name
    4. None of the given
    Show answer

    C. Same as class name

  25. When an object is passed by reference to constructor, the constructor that is executed is _____

    1. Inline
    2. Default
    3. Static
    4. Copy
    Show answer

    D. Copy

Advertisement