1.

What is a constructor? Give the rules of writing a constructor function.

Answer»

Constructor is a special member function that is used to initialize the data members of an object. 

The rules for writing a constructor function are:

  • They should be declared in the public section
  • They are invoked automatically when the objects are created
  • They should not have return types, therefore they cannot return values
  • They cannot be inherited
  • They can have default arguments
  • These cannot be static

An object of a class with a constructor cannot be used as a member of a union.



Discussion

No Comment Found

Related InterviewSolutions