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

Nick Vitsinsky
Nick Vitsinsky
7,246 Points

How to define member field?

Ok, so I read all the topics related to "m" before the variable, but still don't get it, how do we define whether it is a member field or not, should it be a member or not?

Charles Cloud
Charles Cloud
6,134 Points

Can you clarify your question?

3 Answers

Chaz Hall
Chaz Hall
1,970 Points

I understand it as if the class were a chess club and a member variable is a player of that chess league. The m would be something similar to a membership card in that all players have one. I don't know if that helps but I know I need easy breakdowns.

Nick Vitsinsky
Nick Vitsinsky
7,246 Points

Maybe a bit easier to answer is when to declare String mVariable and when String variable?

Charles Cloud
Charles Cloud
6,134 Points

Ohhh got ya. It is simply what convention you want to follow. The prefixing of the m is simply a standard used in development of android applications, most other places the standard is to not use a prefix. So in essence, if you are developing for android use the m, otherwise don't.

Nick Vitsinsky
Nick Vitsinsky
7,246 Points

ok, but why Craig called it - member. I assume we can have a member variable without m if we won't use convention. So the question is mostly how to understand should this variable be a member variable or not. Maybe I'm confused because English is not my native language. urgh

Charles Cloud
Charles Cloud
6,134 Points

Member simply means that it belongs to the class. It is a member of the class as it were. So the prefix does nothing as far as making it a member variable or not, the m just stood for member. As far as behavior goes however, the m makes absolutely no difference. The m is not what makes it a member variable, it simply stands for member and it is convention to use it at certain times (aka Android dev)