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 trial

Android Build an Interactive Story App (Retired) The Model-View-Controller Pattern Implementing the Data Model

Suleyman Orazgulyyev
PLUS
Suleyman Orazgulyyev
Courses Plus Student 5,798 Points

Setter 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
yotam laor
1,319 Points

Setter method allows you to change parameter value anytime you call this method. Constructor sets the parameter value only once, when the class is declared.

Suleyman Orazgulyyev
Suleyman Orazgulyyev
Courses Plus Student 5,798 Points

I 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.

yotam laor
yotam laor
1,319 Points

Do you have an example?