• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

member instance variables

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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???
 
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Think of how dumb the average person is. Mathematically, half of them are EVEN DUMBER. Smart tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic