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 Getting Started

What's the point of making mAnswer private?

Okay so when making a variable private it means you don't want the public to access it, that's understandable. BUT why make it private in the first place and then use it mAnswer = answer, wouldn't that make it public again or am I just going crazy? OO languages aren't my thing :(

1 Answer

Craig Dennis
STAFF
Craig Dennis
Treehouse Teacher

Hi Qasim!

This is a method called encapsulation. We are hiding our internal state and only exposing what we want to be public. This allows you to change how we handle things under the covers, but users of the Game don't mind, because we always keep up our end of the deal by making sure the public facing things are real and what they expect.

Here's a weird analogy that might work, try to think about things that you like to keep private, and what things you choose to put out into the world to see. Really think about those private and public keywords that way. Might be too weird ;)

Hope that helps!

It did help thank you :)! Can't wait for more Java stuff. It's a bit sad that Java courses are the least on Treehouse.

Craig Dennis
Craig Dennis
Treehouse Teacher

More on the way every day...I'm just getting started. And we are working on getting an additional teacher.

Have you seen the Java Content Trello Board

Make sure to vote!

I have a course in post-production and another workshop on the way.....moving as fast as I can type/speak/screencast ;)

Craig Dennis Have seen it and already voted on most of them. It's hard to decide to what to vote on since I don't have the knowledge of what is more important than the other. My goal is to become a 'pro' in Java as well as Python (just like you I think by reading your interview on the Treehouse blog). I am learning Java to get into Android a bit so I can merge my Python web application project to an Android app. Any tips on that maybe? What should I learn next after I finish the current courses in the Java section on Treehouse?