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

Malcolm Robertson
Malcolm Robertson
8,478 Points

swapHead

So my question is about the method that Imaginary Chris made.

String before = dispenser.swapHead("Darth Vader");
System.out.printf("It was %s but Chris switched it to %s %n", 
                              before, dispenser.getCharacterNme()):

The output is... "It was Yoda but Chris switched it to Darth Vader"

If the before method is taking Darth Vader as the input why is the before (variable) holding Yoda and not Darth Vader?

Thanks.

Malcolm Robertson
Malcolm Robertson
8,478 Points

Hmm, it is that the method is returning the originalCharacterName while also setting the private String characterName as the charaterName input?