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) Meet Objects Privacy and Methods

Well Done ! I Didn't understand Anything on "Public" and "private" .

Plz Someone Help me !

2 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,457 Points

"public" and "private" control access to members within a class. Marking a member or field "private" restricts access outside of that class. More info in the docs

I can understand how it can be confusing; I know i didn't understand the concept at first when i took a java course. To make it simple it controls whether or not you can access it. The reason why you wouldn't want it to be accessed is because you want to stay constant like the variable in the method. Basically by making it private the only time you can access that variable is within that method and not anywhere else within your line of code.