Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.