Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

member instance variables

 
Gouri SenSharma
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the exact definition of member instance variables?
I ask this question as the Java round up game had a question.

Do member instance variables always get a default value if left unassigned.

Now I know that is TRUE for all instance variables except ones that are marked final.
I have noticed that if you have a final instance variable and if you DONOT assign an explicit
value to it before the constructor completes, a varaible not initialized exception is thrown.

So, keeping the above fact in mind I answered FALSE.

But the round up game counted this as a wrong answer.

Where is my understanding wrong..can somebody correct me???
 
Gouri SenSharma
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry there were typos in the earlier post..so reposting...

What is the exact definition of member instance variables?
I ask this question as the Java round up game had a question.
Do member instance variables always get a default value if left unassigned. ?

Now I know that is TRUE for all instance variables except ones that are marked final.
I have noticed that if you have a final instance variable and if you DONOT assign an explicit
value to it before the constructor completes, a varaible not initialized exception is thrown.

So, keeping the above fact in mind I answered FALSE.

But the round up game counted this as a wrong answer.

Where is my understanding wrong..can somebody correct me???
 
Bob Wheeler
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Anu,

Where is my understanding wrong..can somebody correct me???

I'm with you. I don't think your understanding is wrong.
So what are member instance variables? First of all, there are members (methods and variables).
Each of them can have member modifiers like (static, final, whatsoever). The same is true for
member variables (e.g static and instance). So member instance variables can be final. And as you stated correctly
these final variables HAVE TO be assigned (JLS)
I guess, this is a mistake.

cheers
Bob
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic