+ 1

So when are constructors usually used?

9th Aug 2016, 10:18 PM
Danut Alexandru
Danut Alexandru - avatar
1 Réponse
+ 3
When you need to initialize your object to some known state to start with or perform procedure before the object can be used. Let's say you want to teach someone how to drive. Before the driving lesson could start, you first need a car with gas. So you can get a car in constructor and fill gas in it. As a user, they came to your school just for learning but there are other requirements which user assume you fulfil it.
10th Aug 2016, 7:53 AM
Nick D.
Nick D. - avatar