+ 1
why use construtors
5 Respuestas
+ 7
When you use a constructor and create an object of that class, the constructor is automatically ran. It's also required for what @Amir said.
So if you want any variables or methods to always do something when the object is created (make your own default values) you can use the constructor for that.
Note* every class has a constructor, even if you don't make one, a default one will be provided for you. (from the compiler).
+ 2
for ensure that objects of your class are born valid.
you can 'ask' the user of that class for required dependencies.
0
ok thnku
0
when use
0
because it helps to initialize data at the time of creation so that our program runs fast