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

Christopher Jow
Christopher Jow
625 Points

Order of methods, variables, modifiers, etc.

What is the property order for method, variables, modifiers, etc.? In the video, Craig has "final private string", but above it uses "public final string" or whatever. Just wanting to know what is the best order for things to be declared.

1 Answer

Steven Couture
Steven Couture
2,106 Points

when wanting to make instance variables its best to declare them after opening the class block. by making something public final means it can be used outside the class but cannot be changed after being given a value (most likely from the constructor). When its private final, it can only be used in that class and cannot be changed after given a value (most likely from the constructor)

hope this helps, just comment if you need me to explain better!

Steven Couture
Steven Couture
2,106 Points

and no it doesn't matter what order its in and its better to do it after opening the class block

Christopher Jow
Christopher Jow
625 Points

Ok. Is there an order to those? Example: integers before strings or private before public.