Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialSuleyman Orazgulyyev
Courses Plus Student 5,798 PointsSetter or Constructor?
Hey everyone,
My question is basically in the title, why does Ben use setters and not constructors?
Thanks in advance everyone!
2 Answers
yotam laor
1,319 PointsSetter method allows you to change parameter value anytime you call this method. Constructor sets the parameter value only once, when the class is declared.
yotam laor
1,319 PointsDo you have an example?
Suleyman Orazgulyyev
Courses Plus Student 5,798 PointsSuleyman Orazgulyyev
Courses Plus Student 5,798 PointsI agree, but we don't want to change the values of the variables after the declaration of the class, so after the values are set they are never changed.