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 trialShane Desouza
3,523 PointsDoes the 'public' keyword mean the method or variable name is available to anyone?
Does it mean that it is available to anyone who wishes to use it, as in people who are programming different apps?
2 Answers
Gloria Dwomoh
13,116 PointsNot exactly. Public means it can be accessed by any class (and is also visible to any class) in your package or of another package (though if you use a public class for example in another package you'd need to import it). If you make your code opensource on GitHub or other places, then other programmers can use the actual whole code you have uploaded, that has nothing to do with public/private/protected...though.
Jonathan Herren
475 PointsSo, if it is set to public any "class" in "your" project can access it. Other people that don't have your code can NOT access it, but i understand why you thought that. :)
Shane Desouza
3,523 PointsShane Desouza
3,523 PointsRight... Thanks for that! Makes it a lot easier to understand when it comes to this sort of stuff.
Gloria Dwomoh
13,116 PointsGloria Dwomoh
13,116 PointsYou are welcome Shane :)