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
Michael Bishara
1,911 PointsWhat does "return" actually do?
Please see the following snippet of code:
public String getColor() {
return mColor;
}
What does the "return" mean and what does it do? When would we use it?
Thank you
1 Answer
Daniel Babbev
10,354 PointsSay you want to add A +B = C. To solve this you take A, add it to B and get the result, which is C. You, in computer's terms, return C.
Let A = 1 and B = 5. The computer takes 1, adds 5 and returns 6.
Basically, return is the result of the function.
In your case, the function returns the value of the mColor variable. This makes the mColor easily accessible from other classes.