Why do we need a constructor as a class member?Ī constructor is used to initialize the objects of the class with a legal initial value. Name the different types of constructors used in a class program. Here, Employee() is invoking a default constructor. It is invoked at the time of creating any object of the class. The compiler supplies a special constructor in a class that does not have any constructor.Ī constructor is not defined with any return type.Įvery class must have all types of constructors.Ī constructor is a member function of a class.Ĭonstructor is used to initialize the data members of a class.Ī constructor may have different name than the class name.Ī constructor is likely to be defined after the class declaration.Ĭopy constructor copies functions from one object to another.Ī constructor is a member method that is written with the same name as the class name and is used to initialize the data members or instance variables. Write TRUE or FALSE for the following statements Question 1 The constructor generated by the compiler is known as default constructor. The argument of a copy constructor is always passed by reference. The this keyword refers to the current object. Parameterised constructor creates objects by passing value to it. Question 3Ī constructor is used when an object is created Question 4Ī constructor without any argument is known as non-parameterised constructor. Question 2Ī constructor has return no type. Chapter 7 Constructors Class 10 - APC Understanding Computer Applications with BlueJĪ member function having the same name as that of the class name is called constructor.