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

What does the "m" stands for as a prefix to the variable? Craig said member? What is it for?

Cant' we not use any variable without "m"?

1 Answer

The m for member is a naming convention, and isn't needed for the code to work. However, it will make the source code easier to understand, as a member variable is one that limits it's scope to the class that it's in. Member variables are therefore made private for the most part, so they are working parts of the object not exposed to the outside world. Think of a radio, and how there's a lot of parts inside a radio that the user doesn't need to know about, that are inside the radio in order for it to work. The m in front of the member variable helps us remember that this value can only be accessed inside the object, like a transistor inside a radio.

Wow! quick response. Thanks.

No problem, anytime Jim! Happy coding!

Ken Alger
Ken Alger
Treehouse Teacher

Nicolas;

Great explanation!

Jim;

You will also find the this.varName used frequently in lieu of the m prefix to varName. They, typically, mean the same thing but some programmers like m while others stick with the this. version.

Happy coding,

Ken