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 trialDean Onizuka
4,753 Pointswhat exactly is a member variable again?
so whats a member variable again? and how is it different from a regular variable? i know he went over it in the video... that part just slipped my mind lol
2 Answers
Saad Anjum
6,408 PointsA 'member variable' is a variable that is defined inside an object and is accessible by all its methods.
There are other types of variables as well:
- 'local variables' which is defined inside a block of code or a method. 'Local variables' are not accessible by other methods of the class.
- 'Parameters' are variables inside a method declaration. These are not accessible by other methods of the class either.
They are all variables.
shezazr
8,275 PointsA normal variable is something you define ANYWHERE..
member variable is also a variable BUT you define it inside a class (e.g. class property so animals can have a property called legs etc)..
btw: not nitpicking but can people start to use google and then post here if they don't understand or get the answers..
arabasz
1,949 Pointsarabasz
1,949 PointsSo it's like a variable that's a member of a club? While other variables don't need to belong to a club?
For example, I might make a member variable named "fruitColor" that is a member of the object "fruit". No other objects should have a "fruitColor" because my other objects are things like "vegetables" and "utensils". Membership is not allowed because it wouldn't make sense.
Er... does that analogy work?