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 trialDerick Brown
7,361 PointsWhy is the class FactBook public?
I'm still a little new to the "private vs public" concept when it comes to Java but I'm still learning lol. So with that being said, why would the class FactBook be public? I would think to set this to private so it can't be changed by anyone (assuming a user can somehow access this information from the front-end).
If my question doesn't make any sense then maybe I need a little more clarity on when to set something to private vs public so feel free to give it to me! lol
2 Answers
Philip Gales
15,193 PointsPublic means other classes can access. Private means only that class can access. In between there is protected. Protected means other classes can see it, but other packages can not.
For now, while you learn, I would just default to public unless a tutorial or example says otherwise.
FactBook is a public class because all classes are public. More specifically, you want other classes (like the main class) to access it, or its methods. This means it will need to be public.
Derick Brown
7,361 PointsAhhh okay cool! Thanks for the explanation Mr.Philip.
Philip Gales
15,193 PointsNo problem. Do you mind up-voting my answer though?
Derick Brown
7,361 PointsYes sir. Sorry about that.