Dinu Comendant2,791 Points
Why getCharacterName gets different values?
PezDispenser dispenser = new PezDispenser("Yoda"); System.out.printf("This dispenser is %s %n", dispenser.getCharacterName() ); String before = dispenser.swapHead("Darth Vader"); System.out.printf("It was %s but now is %s %n", before, dispenser.getCharacterName());
in the first dispenser.getCharacterName we get Yoda, but in the second we get Darth Vader, why is that? the value of Yoda was transferred to originalCharacterName, so in the method getCharacterName it should return Darth Vader