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 triallowell seitz
631 PointsWhy does java "return" statement variable name that it will be returning not have to match the expected variable name i
Why does java "return" statement variable name not have to be the same expected variable name in the method name. What happens when you return the orginalCharacterName, but the method is expecting CharacterName as the return argument/variable. public String swapHead(String characterName) { String originalCharacterName = this.characterName; this.characterName = charaterName; return originalCharacterName; }
2 Answers
Fahad Mutair
10,359 Pointshi lowell seitz ,
public String swapHead(String characterName)
(String characterName) this is the parameter not the return and when you call method with argument it will be set to this parameter
public String swapHead < the string word here means it should return String variable that's why we typed this line return originalCharacterName; and it already declared as String at this line String originalCharacterName
lowell seitz
631 PointsThank you I understand now