What is the difference between objects and constructors ?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

What is the difference between objects and constructors ??

2nd Nov 2016, 1:33 PM
Shruti Singh
Shruti Singh - avatar
4 Answers
+ 4
Constructors are methods of a class which activate when an object is created. And object is an instance of a class. The object can access the class' functions and/or variables.
2nd Nov 2016, 1:42 PM
nedas
nedas - avatar
+ 4
How do I even do that? Constructor is a method/function in a class that activates when an object is cteated. An object is what calls the methods/functions in the class. Thats pretty much everything about them.
2nd Nov 2016, 2:08 PM
nedas
nedas - avatar
+ 2
Nedas, please elaborate
2nd Nov 2016, 1:49 PM
Shruti Singh
Shruti Singh - avatar
+ 1
a class is a blueprint for it's objects. a constructor is a function inside a class which automatically give the objects '''initial values and attributes'''. so when God created the human class he wrote the class constructor like this. function __constructor(breed,kill){ breed = this.breed; kill = this.kill; }. because of this there is an Aleppo.
2nd Nov 2016, 11:24 PM
Emrullah ÖZALP
Emrullah ÖZALP - avatar