0

What is constructor?

24th Mar 2016, 2:15 PM
Amita Rana
Amita Rana - avatar
1 Answer
+ 1
It is a method invoked during the object instantiation (creation); as the name suggests it is involved with object construction. Simple use is when we need to initialize some attributes of the object, so it make more sense. Example: We want to avoid someone to initialize an object of type/class Person without the person name (another programmer could forget it; causing future problems).
11th Apr 2016, 4:39 AM
Rafael Delalibera Rodrigues
Rafael Delalibera Rodrigues - avatar