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 Harnessing the Power of Objects Constants

Kevin Brender a Brandis
Kevin Brender a Brandis
1,382 Points

how to use final?

Why did the final switch places

class PezDispenser {
  public final int MAX_PEZ=12;

  final private String characterName;

with the public int its after public

with private string its before private

1 Answer

Michael Hulet
Michael Hulet
47,912 Points

Java isn't my main thing and it's been a long time since I've used it, so this may be wrong, and if it is, somebody please correct me.

public declares the visibility of the symbol, int and string both declare the type of the variable, and final means that the value is constant and can't be reassigned. Java doesn't really care what order you type those in, as long as they're all before the variable name and initial assignment. So, pick your favorite order for those keywords, and it's perfectly valid, but I think it's most common to write it like public final int