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 trialEthan Morris
19,474 Pointsusing public final instead of private final for characterName?
Now that we have learned about the final modifier is it not better to use it along with public for the characterName variable? e.g. "public final String characterName;"
This way the property can still be access with dispenser.characterName instead of having to create a getter method to return it. The final modifier achieves the intended purpose of making characterName private in an earlier video which was to stop it being updated once created.
1 Answer
Traian Butaru
5,451 PointsI think you get the same thing, but youβre missing on benefits of the encapsulations. Maybe, at a later date, you would like to do some manipulations before returning the characterName. Itβs easier just to modify the getter than creating an extra method and changIng all the code to work with your new method.