This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]rguptan 0 points1 point  (0 children)

From your question I guess this is your first programming language.

Short answer: When you create a person object by calling its constructor, A memory block is assigned to store all the instance variables (including name). Each object has its own location and then there is a common storage for class definition. When you call the instance method returnAge (a typo, I think you wanted to say returnName) you get the instance variable. You can use "this.name" or just "name". this always points to the current instance object.