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 (Retired) Creating the MVP Prompting for Guesses

Mike B
Mike B
10,424 Points

When to set a variable to private?

I'm not quite understanding when I should set a variable to private. It seems as though any member variable should be set to private so that they can't be accessed directly. Is it possible to set too many variables to private?

2 Answers

It's almost always best practice to set your member variables private. And don't worry, there's no such thing as setting too many variables as private since every class will have different amount of variable in order to work properly, so you can't set an ultimate number. The confusion will be gone with time, just keep at it.

Mike B
Mike B
10,424 Points

Thanks for the reply...I was getting worried that I was making things private that I shouldn't be.