- 1

Why to use constructors?

What's the reason to use constructors when that make the same things of the object properties?

26th Jun 2016, 1:36 AM
Juan Camilo Arroyave Rico
Juan Camilo Arroyave Rico - avatar
4 Answers
+ 2
constructors can initialize your class/struct object while they are being created...
26th Jun 2016, 9:40 AM
Mukul Kumar
Mukul Kumar - avatar
0
if u want something compulsory like you have a class for doing database activities and connection is required compulsory the you can add that into constructor.
26th Jun 2016, 4:06 PM
nitin sharma
nitin sharma - avatar
0
to initialize the members of the class i mean (data of your class)
2nd Apr 2017, 12:32 PM
Ahmed Helal Ahmed
Ahmed Helal Ahmed - avatar
- 2
when you create a object of class with new keyword that time it call constructor may be you declared as explicitly or if not then compiler take care for declared implicitly constructor for initialization default value of all variables of class.
26th Jun 2016, 9:16 PM
Chandan Sharma
Chandan Sharma - avatar