why to make a contructor and assign a value? Isint that same as just assigning a value....??? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

why to make a contructor and assign a value? Isint that same as just assigning a value....???

31st Aug 2016, 5:39 AM
Siddharth J Namboodiri
Siddharth J Namboodiri - avatar
2 Answers
0
If you assign a value outside the constructor, you are assigning a static value that all instances of that class share. Assigning it inside gives each object it's own value to be used independently of the other objects.
31st Aug 2016, 5:43 AM
James
James - avatar
0
ohh got it.... thanx alot...
31st Aug 2016, 5:45 AM
Siddharth J Namboodiri
Siddharth J Namboodiri - avatar