0

Greetings fellow programmers!

So I've been learning java for 2 months and its been a really awesome experience and journey. There's a confusing thing in java I still don't know why I can do it. The idea is using using instance variable in conjunction with objects.

How come I can specific the objectname.instance variable associated with the object? What's this process called?

1
  • 3
    I have no idea what you're asking. Could you clarify? Commented Nov 3, 2011 at 15:06

2 Answers 2

3

It's called dereferencing, the same as calling a method via objectname.method(). Note that strictly speaking, it's not the object's name, but the name of the reference (there can be many references with different names refering to the same object).

Note also, that it's considered better to encapsulate instance variables by making them private and providing set/get methods if necessary.

Sign up to request clarification or add additional context in comments.

Comments

1

That'd be dereferencing, I believe. It's not as explicit in Java as in languages that confront you with concepts like pointers or memory offsets.

2 Comments

Thanks! It makes more sense now!
@NicholasKong Once you feel comfortable with Java and have done some advanced work in the language (we're talking a time frame of years here), it's definitely worth learning something lower-level like C or C++. I find that getting a good understanding of low-level concepts that are abstracted away by newer languages will improve your skills as a programmer and make you understand any new language far quicker.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.