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 trialkristoffer tølbøll
1,337 PointsWhy is it when you declare Strings at first you write m in front of it like: String = mArtist;
Why is it when you declare Strings at first you write m in front of it like: String = mArtist; but in the constructor its just public void song (artist){ }
2 Answers
Manish Giri
16,266 PointsThat is a notation followed in Android code -
Non-public, non-static field names start with m.
Eugenio Villarreal
8,041 Points"m" stands for Member Variable, a variable which belongs to the class. You can also use "this." as a variable, it is part of Java Syntax
There are used to distinguish between the class variable and the method´s variable.
For example here:
public Song ( String title, String author){ mTitle = title; mAuthor = author; }
You use "m" to distinguish between the class variable declared beforehand and the variable entered in the constructor. It read better and this way you don´t have title = title... :s