+ 1

why use construtors

11th Apr 2017, 1:26 PM
Rishi Mishrq
Rishi Mishrq - avatar
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).
11th Apr 2017, 3:09 PM
Rrestoring faith
Rrestoring faith - avatar
+ 2
for ensure that objects of your class are born valid. you can 'ask' the user of that class for required dependencies.
11th Apr 2017, 1:38 PM
AmirMahmood Ahrar
AmirMahmood Ahrar - avatar
0
ok thnku
11th Apr 2017, 1:39 PM
Rishi Mishrq
Rishi Mishrq - avatar
0
when use
11th Apr 2017, 1:40 PM
Rishi Mishrq
Rishi Mishrq - avatar
0
because it helps to initialize data at the time of creation so that our program runs fast
12th Apr 2017, 9:17 AM
PRANJAL AGNIHOTRI
PRANJAL AGNIHOTRI - avatar