0

What's the use of constructors ?

Why to use a constructor if we can use a user-defined function instead?

28th Sep 2018, 9:59 AM
Aman Jain
Aman Jain - avatar
2 Answers
+ 11
Constructor is always called immediately after creating an object of class. It's comfortable to use it to set default and entered values.
28th Sep 2018, 10:38 AM
Aleksander Szczepura
Aleksander Szczepura - avatar
0
A constructor is like a "function". This function will be called and executed everytime an object of that class is created. You can use constructors to define default values of variables in the class, and run other functions within the class. https://code.sololearn.com/cakcnGGVEzHb/?ref=app https://code.sololearn.com/cEpnHkwLekCJ/?ref=app
28th Sep 2018, 4:35 PM
Max SepĂșlveda
Max SepĂșlveda - avatar