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

Android Build a Simple Android App (2014) Improving Our Code Simple Refactoring: Creating a Class

Shane Desouza
Shane Desouza
3,523 Points

Does 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

Not 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.

Shane Desouza
Shane Desouza
3,523 Points

Right... Thanks for that! Makes it a lot easier to understand when it comes to this sort of stuff.

You are welcome Shane :)

So, 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. :)