0
Why we need object constructor to construct any object?
3 Réponses
+ 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.
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.
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"