What is constructor ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

What is constructor ?

Answer

21st May 2019, 11:49 AM
Ankit Mewada
Ankit Mewada - avatar
5 Answers
+ 3
Constructor is a function with same as class name and do NOT have any return type and it will call when instance of that class is created. Types of cinstructor 1. Default Constructor 2. Parameterized Constructor 3. Copy Constructor
21st May 2019, 12:57 PM
Malhar Naiya
Malhar Naiya - avatar
+ 16
Constructor is class member function and it's name is same as class name. It is used to initialize values of variables and called automatically when object of class is created.
23rd May 2019, 3:56 AM
Priyanka♥️
+ 3
Constructor is a function with same as class name and do NOT have any return type , it call implicitly and in special cases it also call explicitly
23rd May 2019, 1:35 AM
Ameer Wajid Ali
Ameer Wajid Ali - avatar
+ 2
Constructor can be used to initialize dafault values, establishing connections, allocate memory, allocating resources etc. Can be done when object is created. So, we can put that code in constructor.
21st May 2019, 12:59 PM
Malhar Naiya
Malhar Naiya - avatar