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

Using "m" for member fields.

Hello again,

So watching the video and taking the quiz, it seems like this is a pretty big thing. But while I understand WHAT it is, I don't see why it's important to have. Could someone clarify?

Thanks in advance, Harry.

1 Answer

It isn't hugely important but it does make code clearer to read.

Take, for example, a constructor for a class with a member variable:

public class UseAnM {

  private String mExample;

  public UseAnM(String example) {
     mExample = example;
  }

Which is fine, but if you don't use the 'm' prefix, the constructor would have the line example = example; in it, which is confusing. You could probably elaborate with self.example = example; but I get that's not the point.

I hope that makes some sense ... I'm no expert!

Steve.

Alright, thanks.