0
What's the use of constructors ?
Why to use a constructor if we can use a user-defined function instead?
2 Réponses
+ 11
Constructor is always called immediately after creating an object of class. It's comfortable to use it to set default and entered values.
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