C++ - Constructors and Destructors
CBSE Class 12 - Computer Science - Questions and Answers
Q1: What is a constructor? How it is different from other member functions?
Answer: A constructor is a special member function that must be defined with the same name as the class and it is used to initialize the data members of the class. Constructor is invoked automatically when an object of a class is created. Constructors unlike other functions cannot return values, so they cannot specify a return type (not even void ).Generally, constructors are declared public.
Q2: Name the types of constructors.
Answer: Types of constructors:
① Default Constructor (No argument constructor)
② Parameterized Constructor (Overloaded Constructor)
③ Copy Constructor