0

Why we create constructor in classes

What is the use of constructor or why we need it

13th Apr 2019, 1:26 PM
Tony Stark
Tony Stark - avatar
6 Answers
13th Apr 2019, 2:11 PM
Aleksander Szczepura
Aleksander Szczepura - avatar
+ 3
Constructor is called everytime you create an object of its class. You can use it for example to set default values of object properties.
13th Apr 2019, 1:43 PM
Aleksander Szczepura
Aleksander Szczepura - avatar
+ 3
Exactly
13th Apr 2019, 2:16 PM
Aleksander Szczepura
Aleksander Szczepura - avatar
+ 2
Aleksander Szczepura So it is called automatically when you create its object p=Person("jack") And you passed the name in it we dont need to call it like other methods
13th Apr 2019, 2:15 PM
Tony Stark
Tony Stark - avatar
0
Aleksander Szczepura can you define it with example
13th Apr 2019, 1:45 PM
Tony Stark
Tony Stark - avatar
0
Thanks bro
13th Apr 2019, 2:17 PM
Tony Stark
Tony Stark - avatar