0

Why we need object constructor to construct any object?

18th Jun 2016, 1:16 PM
sorath Peetamber
sorath Peetamber - avatar
3 odpowiedzi
+ 1
We use constructors to create similar objects. We can set up a constructor to build an object with some number of properties and then build that kind of object with ease. They're like a blueprint. Not using a constructor, we must set up each object individually. Although they can still be the same kind of object that isn't a requirement. If you're building similar objects, use a constructor. As an example, consider building "people" objects. If you want them all to have a name and an age, a constructor would be appropriate. If, however, you wanted a "person" object and a "dog" object you could forego the use of constructors as you're building two different objects.
31st Jul 2016, 2:38 AM
Max Beck
Max Beck - avatar
0
now I have got it that we use constructor that we can create the objects of same type just using a different keyword. but if we're not using constructor than we can't use the objects of same type.
23rd Jun 2016, 5:06 AM
sorath Peetamber
sorath Peetamber - avatar
0
@sorath I wouldnt use the the words "same type" There isnt really a type. But the object constructed follows the same definition. Its not the same like in other common object oriented programming languages like java or c#. Or just put it into brackets ;) like its a "type"
23rd Jul 2016, 11:49 AM
MarquisBs
MarquisBs - avatar