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 trialYoussouf Conde
525 Pointsif getCharacterName is a method, why can't I just put the value I want to return in the parentheses?
I don't really understand why I have to state return characterName. Can the value you want to return be directly incorporated into the method? Like this: public String getCharacterName("Yoda");
if that's impossible, why is it impossible?
Thanks.
1 Answer
Peter Vann
36,427 PointsHi Youssef!
I'm not much of a Java programmer, but I have to assume that you'd want to do something like this:
public String getCharacterName(String name) {
return name;
}
And then pass "Yoda" to the function when it's called.
And even then you won't see the return value anywhere unless you do something like assign the return value to a variable and print that value to the screen/console or put the called function in a print statement directly.
In most, if not all, languages, you need to explicitly return the value that the function should return, otherwise the return value is void, null, false, or undefined, etc.
I hope that helps.
Stay safe and happy coding!