• Post Reply Bookmark Topic Watch Topic
  • New Topic

Auto Initialization  RSS feed

 
Mohnish Khiani
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which types of variables are automaticaaly initialized and which ones are not??
 
Ireneusz Kordal
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Refer to the Java Language Specification:
http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.12.5
 
Mohnish Khiani
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So that means only method local variables are the ones that are not given any values by default and must be explicitly initialized...am i right???
 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What did it say in the link? It said local variables must be initialised or assigned before use. Of course the 0/null values given to fields will probably have to be re-assigned, otherwise there will be incorrect results or NullPointerExceptions.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!