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

Android Build a Weather App (2015) Working with JSON Introducing JSONObject

Steven Strouble
Steven Strouble
4,128 Points

Why "private CurrentWeather currentWeather;" and not "... currentWeather = new CurrentWeather();"?

I suppose this is just more of a general Java/Android question rather than specific to this lesson.

1 Answer

Ricky Catron
Ricky Catron
13,023 Points

The keyword "private" lets the program know that only this class can use that variable.

private CurrentWeather currentWeather; is declaring the variable so it can be initialized later in the program this works well for if it needs to be created using input from the user.

CurrentWeather currentWeather = new CurrentWeather(); does both declaration and initialization all at once. This can save time but like i said the other way is sometimes better for giving the variable a value based on input.

Mostly this is just a style choice and not something you really need to worry about.

Goodluck! --Ricky