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

Java Java Objects Delivering the MVP Validating and Normalizing User Input

Jasper Kop
Jasper Kop
10,423 Points

How can the normalizedGuess and the applyGuess have both a declaration of the char letter?

In the 'normalizeGuess' we define the char letter but in the applyGuess there is also a char defined as letter.

I assume that both char's are in a different method and so in a different scope(?) but why haven't you chosen to declare the variable char on forehand, so you don't have to declare it twice?

I really would like to get my head around it, because I understand the code but I would have never used the double declaration with the same name.

1 Answer

Mark Sebeck
MOD
Mark Sebeck
Treehouse Moderator 37,901 Points

Hi Jasper. Yes you are correct. Each method is it's own scope so variables declared in a method are only available to that method. For this example that is what the instructor wants. He only wants the letter that is passed into the method. If you declare letter outside the method it would be global like the answer String. For answer that makes sense since it will never change and needs used by other methods. For letter he only wants it used and to be available inside the methods.